title: Rendering a dictionary in Jinja2
body: <p>I'm playing with a url shortener (basing it on the Shortly demo app from Werkzeug).</p>
  <p>I have a dict like this -</p>
  <pre><code>('1', {'target': 'http://10.58.48.103:5000/', 'clicks': '1'})
  ('3', {'target': 'http://slash.org', 'clicks': '4'})
  ('2', {'target': 'http://10.58.48.58:5000/', 'clicks': '1'})
  ('5', {'target': 'http://de.com/a', 'clicks': '0'})
  </code></pre>
  <p>which is returned in url_list and used by render_template</p>
  <pre><code>def on_list_urls(self, request):
      url_list = self.get_urls()
      return self.render_template('list_urls.html',
          url_list = url_list
      )
  </code></pre>
  <p>the template list_urls is pretty simple -</p>
  <pre><code>{% extends &quot;layout.html&quot; %}
  {% block title %}List URLs{% endblock %}
  {% block body %}
    &lt;h2&gt;List URLs&lt;/h2&gt;
    &lt;ul id=&quot;items&quot;&gt;
    {% for item in url_list %}
      &lt;li&gt;{{ item }}&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
  
  {% endblock %}
  </code></pre>
  <p>Thing is, I can't seem to access the items in the dict.</p>
  <p>The line</p>
  <pre><code>&lt;li&gt;{{ item }}&lt;/li&gt;
  </code></pre>
  <p>is where I'm focussing attention. As above, I get a list of the keys in the dict.</p>
  <pre><code>&lt;li&gt;{{ item[&quot;target&quot;] }}&lt;/li&gt;
  </code></pre>
  <p>returns nothing. None of the
  {{ user.url }}&quot;&gt;{{ user.username }}
  type stuff in the docs seems to work.</p>
  <p>Ideas please? Newbie - be gentle. Thanks.</p>
  <p><strong>Update</strong></p>
  <p>Thanks for the responses.</p>
  <p>Ewan's answer works, but uses a list of dicts. I want to pass a dict and render that (because I want a non-integer index of items). Does Jinja do that?</p>
  <p>Also - I mis-represented url_list. It's more like this -</p>
  <pre><code>{'a': {'target': 'http://testing.com/test', 'clicks': '0'}, 
  '1': {'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
  '3': {'target': 'http://slash.org', 'clicks': '4'}, 
  '2': {'target': 'http://10.58.48.58:5000/', 'clicks': '1'}}
  </code></pre>
  <p>Further experimentation - passing a dict produces an error about a list object.</p>
  <pre><code>{% for key in url_list.iteritems() %}
  </code></pre>
  <blockquote>
  <p>UndefinedError: 'list object' has no attribute 'iteritems'</p>
  </blockquote>
  <p>Thanks again.</p>
  <p>Still baffled by why it thought I was passing a list but got it working now.</p>
  <pre><code>{% for key, value in url_list.iteritems() %}
      &lt;li&gt;{{ key }} - {{ value[&quot;target&quot;] }} - {{ value[&quot;clicks&quot;] }}&lt;/li&gt;
  </code></pre>
  <p>prints out everything. Many thanks.</p>