On Tue, Feb 26, 2008 at 3:21 AM, Jose Jiménez <[EMAIL PROTECTED]> wrote:
>
>  How can i access to the key and the value of all elements of a
>  dictionary? If i do: for a in variable, a is the key, but i can't
>  access its value.
The {% for key,value in list %} syntax was added in the trunk. In
0.96, you can't roll out tuples in a for loop; you are restricted to
saying  {% for value in list %}. However, if "list" is a list of
tuples, you can use {{ value.0 }}, {{ value.1 }} to reference elements
in the tuple.

By default, iterating over a dictionary {% for key in dict %} provides
a list of keys. However dict.items() will provide a list of (key,
value) tuples (Tom's suggestion will also work - it provides an
iterator over tuples). If you then use {% for entry in dict.items %},
{{ entry }} will be a tuple, {{ entry.0 }} will be the key, and {{
entry.1 }} will be the value for the key.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to