I'm trying to understand how dictionary lookups work in templates. To that end I'm passing in a dictionary of lists like this,
allyears = {"2002":["a","b","c"], "2003":["a","b","c"]} return render_to_response('press/inthepress_index', "allyears":allyears,) into the template, ie in the webpage, show all thingies for each year. I have a corresponding fragment like this in a template: [[[ {% for yearkey in allyears.keys %} <h3>{{yearkey}}</h3> <ul> {% for entry in allyears.yearkey %} <li>{{entry}}</li> {% endfor %} </ul> {% endfor %} ]]] which produces this: [[[ 2002 2003 ]]] ie the lookup allyears.yearkey is not returning the list value even though the yearkey is taken directly from the dict's keys. I think this is expected behaviour as the template engine will be looking for a field called "yearkey" on the allyears dict rather than evalauting it first *. If so, is there an idiom for generically looping over dictionaries or nested lists in templates? cheers Bill * An aside. If instead of using a key on the allyears dict, I use literals, ie like this: [[[ <h3>2003</h3> <ul> {% for entry in allyears.2003 %} <li>{{entry}}</li> {% endfor %} </ul> <h3>2002</h3> <ul> {% for entry in allyears.2002 %} <li>{{entry}}</li> {% endfor %} </ul> ]]] I get what I'd expect [[[ 2003 * a * b * c 2002 * a * b * c ]]] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---