【发布时间】:2012-01-29 09:09:24
【问题描述】:
我的模板中有以下代码
{% set counter = 0 %}
{% for object in object_list %}
{% if object.attr1 == list1.attr1 and object.attr2 = list2.attr2 %}
<li><a href="{{ object.get_absolute_url }}"> Link {{counter++}} </a></li>
{% endif %}
{% endfor %}
我使用此custom tag 设置变量的值,我想做的是仅在满足if 循环时才增加该值。我知道{{counter++}} 不起作用。但是我怎样才能编写一个自定义标签来完成同样的任务呢?
【问题讨论】: