0

I have the following data in the template

{u'D - content a': [<Person: first_name last_name>, <Person: first_name last_name>, <Person: first_name last_name>],
 u'D - contant b': [<Person: first_name last_name>],
 u'D - content c': [<Person: first_name last_name>]
 }

And I'd like to have it like this:

h2 -> Content a
    list with three people

h2 -> content b
    list with one person

h3 -> content c
    list with one person

But I can't find out how two write it. My attempt:

    {% for key, value in persons %}
        <h2>{{ key }}</h2>
        {{ value }}
    {% endfor %}
falsetru
  • 336,967
  • 57
  • 673
  • 597
Jonas Grumann
  • 10,058
  • 2
  • 18
  • 37

1 Answers1

2

Use dict.items (or dict.iteritems if you use Python 2.x):

{% for item in persons.items %}
    <h2>{{ item.0 }}</h2>
    {{ item.1 }}
{% endfor %}
falsetru
  • 336,967
  • 57
  • 673
  • 597