Django提供了它。你可以使用以下任一方法:
{{ forloop.counter }}索引从1开始。{{ forloop.counter0 }}索引从0开始。
在模板中,你可以执行以下操作:
{% for item in item_list %} {{ forloop.counter }} # starting index 1 {{ forloop.counter0 }} # starting index 0 # do your stuff{% endfor %}
Django提供了它。你可以使用以下任一方法:
{{ forloop.counter }}索引从1开始。{{ forloop.counter0 }}索引从0开始。在模板中,你可以执行以下操作:
{% for item in item_list %} {{ forloop.counter }} # starting index 1 {{ forloop.counter0 }} # starting index 0 # do your stuff{% endfor %}