On Fri, 2006-05-05 at 12:16 +0200, [EMAIL PROTECTED] wrote: > > {% for data in mydict.items %} > > key: {{ data.0 }} > > value: {{ data.1 }} > > {% endfor %} > > Thanks for you answer ... but I still have a problem : how to do a real > dictionnary lookup. > > Here is an example of what I'm trying to do : > > parent = {4 : 'parent1', 5 : 'parent2' } > childs = { 4 : ['child1', child2], 5 : ['child3', 'child4'] } > > {% for data in parent.items %} > key: {{ data.0 }} > value: {{ data.1 }} > <!-- how can I get the child corresponding : childs[key] ? --> > {% endfor %}
Ah, now I see what you are trying do. You can't do this sort of thing (indirectly using one variables value as a parameter to another). This is intentional in Django in order to keep anything like "programming" out of the templates and in your view function. If you need to combine the "parent" and "child" dictionaries in some fashion, that munging should occur in the Python code in your view. Now, at this point, you are either thinking "that's insane" or "that isn't an unreasonable thing to do to stop people going overboard in templates". I happen to be in the latter camp (having worked with languages that are more like PHP in the power they let you put in the template and the maintenance hassle that results). But others are very much in the former camp and that point of view has some validity, too. If you really want to do this in a template, you could write a custom template tag for it, or have a look at some existing custom tags (limodou often posts custom tags to this list, and also have a look at http://code.djangoproject.com/wiki/CookBookTemplateTags , in particular, the CallTag). Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---