On Sun, Feb 14, 2010 at 1:58 PM, Madis <madisv...@gmail.com> wrote:

> Why will this not work or how should i write it to work:
>
> I have the following dictionary:
> projects = {u'NetMinutes': {'chains': [u'Arendus', u'Uuslahendus']},
> u'Veel': {'chains': []}}
>
> Now in a template I want to iterate over them as follows:
> {% for project in projects %}
> <h1 class="a">{{ project }}</h1>
>  {% for chain in project.chains %}
>  -- {{ chain }}
>  {% endfor %}
> {% endfor %}
>
> It iterates over the projects and prints out the project names but
> will not iterate over the project.chains.
> Maybe someone can give me some clues?
>


Iterating over projects just gives you the keys in the dictionary, as
strings. If you also want to work with the values assigned to the keys in
the dictionary you need to iterate over the key,value pairs returned by the
dictionary items() method. Then the value you have in your loop will have a
chains attribute you can access.  For example:

{% for project, chains_dict in projects.items %}
<h1 class="a">{{ project }}</h1>
 {% for chain in chains_dict.chains %}
 -- {{ chain }}
 {% endfor %}
{% endfor %}

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to