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 %-)
So you are talking about the "for" template tag here, not Python code
(best to be clear about that). It also sounds like your "variable" is a
dictionary from your use of the words "key" and "value". Working on
those assumptions:
{% for value in variable.items %}
{{ value.0 }} is the key
{{ value.1 }} is the value
{% endfor %}
Here, variable.items returns a tuple and you can access the items in a
tuple via value.0 and value.1.
Malcolm
--
Why can't you be a non-conformist like everyone else?
http://www.pointy-stick.com/blog/