我需要输出这样的内容:
<div class="scrollable"><div class="items">
<div><img src="1" alt=""/><img src="2" alt=""/><img src="3" alt=""/></div>
<div><img src="4" alt=""/><img src="5" alt=""/><img src="6" alt=""/></div>
<div><img src="7" alt=""/><img src="8" alt=""/><img src="9" alt=""/></div>
</div></div>
来自['1','2','3','4','5','6','7','8','9'等数组。考虑到事实,该阵列是动态的,我该怎么做呢?
答案 0 :(得分:3)
使用divisibleby
内置过滤器。
<div>
{% for item in items %}
<img src="{{item}}" />
{% if forloop.counter|divisibleby:"3" %}
</div> <div>
{% endif %}
{% endfor %}
</div>