 <p>Using a template for loop? You may try this using:</p> <blockquote> <p>forloop.counter</p> </blockquote> <p>see the docs here: <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs</a> </p> <p>Implementation:</p> <pre><code>{% for s in list%} {% for subject in s%} {% for sub in subject %} &lt;div id="{{ sub| getid:forloop.counter+(forloop.parentloop.counter - 1)*total_iterations_inner_loop+(forloop.parentloop.parentloop.counter-1)*total_iterations_mid_loop*total_iterations_inner_loop }}"&gt;&lt;/div&gt; {% endfor %} {% endfor %} {% endfor %} </code></pre>