我在divs
中做了一个循环。第一个div代表第一列,另一个div代表第二列。我只想让它在views.py
中管理。我在views.py
中为两个独立的divs
创建了两个函数。但它并没有显示最后一个函数的结果。它只是给我看第一个功能图片,只有第一个div在工作。你知道吗
index.html
{% static 'images/fulls' as baseUrl %}
{% static 'images/thumbs' as hiUrl %}
<div class="row">
{% for dest in dest1 %}
<div class="col-lg-4">
<a href="{{baseUrl}}/{{dest.img}}">
<img src="{{hiUrl}}/{{dest.img}}" alt="" />
<h3>{{destt.desc}}</h3>
</a>
</div>
{%endfor%}
</div>
{% for destt in dest2 %}
<div>
<a href="{{baseUrl}}/{{destt.img}}">
<img src="{{hiUrl}}/{{destt.img}}" alt="" />
<h3>{{destt.desc}}</h3>
</a>
</div>
{% endfor %}
views.py
def index(request):
dest1 = Destination()
dest1.desc = 'Hello, How arE you?'
dest1.img = '01.jpg'
return render(request, 'index.html', {'dest1':dest1})
def nextt(request):
dest2 = Destination()
dest2.desc = 'Hello, How arE you?'
dest2.img = '02.jpg'
return render(request, 'index.html', {'dest2':dest2})
试试这个
你实际上有两种不同的观点。
index
函数可以用作视图,nextt
函数也可以用作视图。要在当前设置中查看第二个5,必须添加指向nextt
的路由,如果您还没有(我猜您没有)可以从中查看它的函数。你知道吗Django路由指向函数或类而不是模块。你知道吗
另一种可能的解决方案是将
index
和nextt
合并到一个函数中,并使用一个条件来决定要显示哪个视图。你知道吗相关问题 更多 >
编程相关推荐