【发布时间】:2011-11-26 00:23:06
【问题描述】:
我想创建这样的循环:
{% for object in objects %}
{% if object.before != object %}
{{ object }} this is different
{% else %}
{{ object }} this is the same
{% endfor %}
基于https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#for 我不能。真的没有简单的方法可以做到这一点吗?或者我只需要使用计数器并检查objects[counter-1]?
附: .before 是理论上的,objects 是简单的查询列表。我想对在当前循环成员之前遇到的循环成员进行处理。
【问题讨论】: