django模板行的多个项目 [英] django template rows of multiple items
本文介绍了django模板行的多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个目录,其中有一个未定义长度的项目列表。我想吐出一排,每列三列。所以我有以下html:
I'm creating a catalogue, where there is a list of items of undefined length. I want to spit it out in rows with three columns each. So I have the following html:
<div class="row">
<div class="three columns">item 1
</div>
<div class="three columns">item 2
</div>
<div class="three columns">item 3
</div>
</div>
<div class="row">
<div class="three columns">item 4
</div>
<div class="three columns">item 5
</div>
<div class="three columns">item 6
</div>
</div>
我被困在我如何将其作为django模板实现?如何拆分它,以便在三个项目之后启动一个新行?
I'm stuck as to how I can implement this as a django template? How can I split it up so that a new row starts after three items?
推荐答案
尝试这样的东西:
<div class="row">
{% for item in items %}
<div class="three columns">{{ item }}
</div>
{% if forloop.counter|divisibleby:3 %}
</div>
<div class="row">
{% endif %}
{% endfor %}
</div>
这篇关于django模板行的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文