【发布时间】:2019-04-16 15:23:40
【问题描述】:
我想在 Django 模板中循环我的模型查询集。我可以简单地使用 Django for loop 做到这一点,但我不能超过 1 步,这是我的代码
{% for map in maps %}
{% if forloop.counter|divisibleby:2 %}
#Here I can access Maps with index of 1,3,5 and ..
#How can I access map with index 2,4,6 here at the same time sth like Map[forloop.counter+1]
{% endif %}
{% endfor %}
事实上,我想要一种在我的模板中访问 Map[forloop.counter+1] 的方法,但我不知道该怎么做
【问题讨论】:
-
使用
{% else %}? -
不,我不能使用 else,因为我想为 +2 加步