jinja2 itterate through list of tuples
<p>I have a list of tuples called <em>items</em>:</p>

<pre><code>[ (1,2), (3,4), (5,6), (7,8) ]
</code></pre>

<p>I thought I could iterate though using, but it's not working:</p>

<pre><code># Code
output = template.render( items )

# Tempalte
{% for item in items %}
    {{ item[0] }};
    {{ item[1] }};
{% endfor %}
</code></pre>

<p>Any suggestions?  </p>

<p>From the <a href="http://jinja.pocoo.org/docs/dev/api/#jinja2.Template.render" rel="nofollow">documentation</a>:</p>

<blockquote>
  <p>render([context])</p>
  
  <p>This method accepts the same arguments as the dict
  constructor: A dict, a dict subclass or some keyword arguments. If no
  arguments are given the context will be empty. </p>
</blockquote>

<pre><code>from jinja2 import Environment

TEMPLATE = """ 
{% for item in items %}
    {{ item[0] }};
    {{ item[1] }};
{% endfor %}
"""

template = Environment().from_string(TEMPLATE)

items = [(1,2), (3,4), (5,6), (7,8)]

print template.render(items=items)
</code></pre>

<p>While parsing the template, jinja2 will look for a key called 'items' but in your case, there is none, you have to explicitly specify it.</p>

python jinja2