title: Alternate Row Coloring in Django Template with More Than One Set of Rows
body: <p>Django templates offer the builtin tag <code>cycle</code> for alternating between several values at different points in a template (or for loop in a template) but this tag does not reset when it is accessed in a scope outside of the <code>cycle</code>s definition.  I.e., if you have two or more lists in your template, the rows of all of which you'd like to use some css definitions <code>odd</code> and <code>even</code>, the first row of a list will pick up where the last left off, not with a fresh iteration from the choices (<code>odd</code> and <code>even</code>)</p>
  
  <p>E.g., in the following code, if the first blog has an odd number of entries, then the first entry in a second blog will start as <code>even</code>, when I want it to start at <code>odd</code>.</p>
  
  <pre><code>{% for blog in blogs %}
    {% for entry in blog.entries %}
      &lt;div class="{% cycle 'odd' 'even' %}" id="{{entry.id}}"&gt;
        {{entry.text}}
      &lt;/div&gt;
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>I've tried obviating this by patching with the <code>resetcycle</code> tag offered here:</p>
  
  <p><a href="http://code.djangoproject.com/ticket/5908" rel="noreferrer">Django ticket: Cycle tag should reset after it steps out of scope</a></p>
  
  <p>to no avail.  (The code didn't work for me.)</p>
  
  <p>I've also tried moving my inner loop into a custom tag, but this also did not work, perhaps because the compile/render cycle moves the loop back into the outer loop?  (Regardless of why, it didn't work for me.)</p>
  
  <p>How can I accomplish this simple task!?  I'd prefer not to create a data structure in my view with this information pre-compiled; that seems unnecessary.  Thanks in advance.</p>