Python Loop In HTML
<p>I have the following row within a table:</p>

<pre><code>&lt;TR&gt;
    &lt;TD style="text-align:center;width:50px"&gt;{% for z in recentResultHistory %} {{ z.0 }} {% endfor %}&lt;/TD&gt;
    &lt;TD style="text-align:center;width:100px"&gt;&lt;/TD&gt;
    &lt;TD style="text-align:center;width:50px"&gt;V&lt;/TD&gt;
    &lt;TD style="text-align:center;width:100px"&gt;&lt;/TD&gt;
    &lt;TD style="text-align:center;width:50px"&gt;{% for z in recentResultHistory %} {{ z.0 }} {% endfor %}&lt;/TD&gt;
&lt;/TR&gt;
</code></pre>

<p>when the first instance of the <code>{% for z in recentResultHistory %} {{ z.0 }} {% endfor %}</code> runs I get the expected result. When it runs for the second time it produces no results like it is not looping at all.  Do I need to reset the loop in some way?</p>

<p>The variable is created in my django view.py as follows:</p>

<pre><code>        cursor = connection.cursor()

        cursor.execute("""
                        select
                        team,
                        group_concat( concat(result, '-', convert(opponent USING utf8), '-', team_score, '-', opponent_score, '-', mstatus)
                                     order by fixturedate desc
                                    separator '|') as output from plain_result
                        where (select count(*)
                               from plain_result as p
                               where plain_result.team = p.team
                               and p.fixturedate&gt;=plain_result.fixturedate) &lt;= 5
                        group by team
                       """)

        recentResultHistory = cursor.fetchall
</code></pre>

<p>I should be using list(cursor) rather than cursor.fetchall().  Daniel and dkasak gave me the inspiration to look and I found the following which solved my issue:</p>

<p><a href="http://stackoverflow.com/questions/17861152/cursor-fetchall-vs-listcursor-in-python">cursor.fetchall() vs list(cursor) in Python</a></p>

python html for-loop