On 11/10/06, Merric Mercer <[EMAIL PROTECTED]> wrote: > > Kamil, many thanks but your suggestion does not work. I should have > mentioned that I had already tried that. > > I am returning a dictionary nested inside the main dictionary like so:- > > return render_to_response ('myapp/detail.html', { 'key1': value1, > 'key2': value2, 'campaigns':dict1}), so I presume that is why it is not > working in the prescribed manner. > > dict1 is populated by the view and looks like this {'0': value1, '1': > value2, '3':value3, etc }. The values in dict1 are class objects from > my "myapp.models.campaign". > > As mentioned, I can access theese values directly in the template using > the following syntax {{ campaigns.<key value>.<model attribute> }}. For > example, {{ campaigns.0.id }} works fine for that particular instance. > However, I can't seem to iterate through the whole dictionary. >
When you iterate over a dictionary, you're iterating over the *keys* in the dictionary, not the values. ie. In [1]: x = {"a":1, "b":2} In [2]: for each in x: ...: print each ...: ...: a b According to a comment by Adrian on the template documentation page, what you want isn't possible without writing a simple tag or filter. Jay P. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---