Here's a excerpt from a Django template:
<div id="list-of-things">
{% for key in things %}
{% for thing in thing|get_dict_value:key %}
<div id="thing-{{ count }}">{{key}}: {{ thing }}</div>
{% endfor %}
{% endfor %}
</div>
things is a dict and get_dict_value:key is simply thing[key]. What's needed in the final page is:
<div id="thing-1">A: First thing</div>
<div id="thing-2">A: Second thing</div>
<div id="thing-3">B: Third thing</div>
...
...which means that I need some way of altering the count variable. Using forloop.counter here causes there to be duplicate values as the counter resets for each time through the outer loop.
There doesn't seem to be any way to set a variable in this loop, so is there another means whereby count might be incremented as required?
Here's something you can do
In the views
import itertools
counter = itertools.count()
# pass `counter` to the template
In the template
{{counter.next}}
to display and increment the counter regardless of the loop you're in.