you can also use with
Caches a complex variable under a simpler name. This is useful when accessing an βexpensiveβ method (for example, one that gets into the database) several times.
{% for outerItem in outerItems %} {% with forloop.counter as outer_counter %} {% for item in items%} <div>{{ outer_counter }}. {{ item }}</div> {% endfor %} {% endwith %} {% endfor %}
if using a high version of django you can use
{% with outer_counter = forloop.counter %}
I checked Django 1.4.x - Django 1.9.x supports two methods.
this is more understandable when they have many cycles
WeizhongTu Jun 29 '16 at 8:56 2016-06-29 08:56
source share