python - 在 django 的模板(index.html)中在哪里创建循环?
问题描述
两列有两个div
。我想在其中做一个循环,这样我就不必重复了。section
我在标签上方然后在标签之后尝试了一个循环,section
但它不起作用。相反,它显示了两次图片。
{% static 'images/fulls' as baseUrl %}
{% static 'images/thumbs' as hiUrl %}
<section class="thumbnails">
{% for dest in dests %}
<div>
<a href="{{baseUrl}}/{{dest.img}}">
<img src="{{hiUrl}}/{{dest.img}}" alt="" />
<h3>how are you</h3>
</a>
</div>
<div>
<a href="{{baseUrl}}/{{dest.img}}">
<img src="{{hiUrl}}/{{dest.img}}" alt="" />
<h3>Lorem ipsum dolor sit amet</h3>
</a>
</div>
{% endfor %}
</section>
解决方案
利润。
{% static 'images/fulls' as baseUrl %}
{% static 'images/thumbs' as hiUrl %}
<section class="thumbnails">
{% for dest in dests %}
<div>
<a href="{{baseUrl}}/{{dest.img}}">
<img src="{{hiUrl}}/{{dest.img}}" alt="" />
<h3>how are you</h3>
</a>
</div>
{% endfor %}
</section>