title: Django template -- render a list of dictionaries with incrementing values
body: <p>Without incrementing a template variable, which would be a hacky way to do it, how can I "remember" which level my subskill variable is at and correctly "increment" the level counter in a Django template? </p>
  
  <p>I have a list of dictionaries that looks like this: <code>[{'level': 0, 'skill': 'style a page using CSS'}, {'level': 0, 'skill': 'download JSFiddle'}, {'level': 1, 'skill': 'learn django'}, {'level': 2, 'skill: 'customize a template'}]</code></p>
  
  <p>and I want to render it like this:</p>
  
  <p><a href="https://i.stack.imgur.com/zplhn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zplhn.jpg" alt="enter image description here"></a></p>
  
  <p>But I can't figure out a way to properly increment a counter variable in a django template. </p>
  
  <p>This is what I'm currently using:</p>
  
  <pre><code>{% with level=0 %}
  &lt;h1 align="center"&gt; Level: {{level}} &lt;/h1&gt;
  {% for subskill in subskills %}
  
    {%if subskill.level &gt; level%}
  
      &lt;h1 align="center"&gt; Level:{{level|add:1}} &lt;/h1&gt;
    {%endif%} ... {%endfor%} {%endwith%}
  </code></pre>
  
  <p>What I have right now will only ever increment level to one, but this increment isn't stored. So it goes Level 0, Level 1, Level 1, Level 1 </p>