On Fri, 2006-05-05 at 11:46 +0200, [EMAIL PROTECTED] wrote:
> Hi all,
> 
> I've trouble to understand how it is possible to deal (i.e. work) with
> python dictionnaries in django templates
> 
> Say I have a dictionnary that is called mydict, how can I iterate
> through it's keys/values : I can get the keys ... 
> 
> {% for keys in mydict%}
> 
> {{ keys }}
> 
> {% endfor %}
> 
> ... but how can I get the values ? mydict.keys does not because (I
> guess) the lookup is for mydict['keys'] ...

Somebody else asked this exact question earlier today (and got an
answer). You use the "items" function to get back a tuple (assuming you
want both keys and values) and then reference the first and second
elements of the tuple:

        {% for data in mydict.items %}
            key: {{ data.0 }}
            value: {{ data.1 }}
        {% endfor %}

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to