On Sun, Feb 15, 2009 at 3:07 PM, nivhab <yaniv.ha...@gmail.com> wrote:
> > Thanks for the fast reply! > This generates the following error: > 'for' statements with five words should end in 'reversed' > > And as I have just found out, this error cannot be solved in 0.96 > version. So it seems there is no way of doing such and iteration in > this version. Only 1.0 or DEV versions. > > On Feb 15, 9:57 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > > On Sun, Feb 15, 2009 at 2:47 PM, nivhab <yaniv.ha...@gmail.com> wrote: > > > > > Does anyone know of a way to traverse a list in templates in a dynamic > > > way? > > > Let's say I have the following list: > > > {'message': [u'This field is required.'], 'sender': [u'Enter a valid e- > > > mail address.']} > > > > > and I do not know in advance the keys for this list. I would like to > > > iterate through it and display its content (keys and values) in a > > > dynamic way in a template. Can it be done? > > > > > Thanks in advance! > > > > First of all that's not a list, it's a dictionary, but you can iterate > over > > a dictionary just as easily: > > > > {% for key, value in dictionary %} > > {{ key }}: {% for v in value %} {{ v }}{% endfor %} > > {% endfor %} > > > > -- > > "I disapprove of what you say, but I will defend to the death your right > to > > say it." --Voltaire > > "The people's good is the highest law."--Cicero > > > a) I made a typo in my original post for those who are on 1.0 that should be {% for key, value in dictionary.iteritems %} b) Yeah, this isnt' possible on .96, what you can do is iterate over the keys {% for key in dictionary %} and then write a filter or tag to get the item out of the dictionary by key. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---