On Thu, 2009-07-30 at 11:14 +0200, Salvatore Leone wrote:
> Hi,
>
> I pass to my template a dictionary of answer -> [attach_list]
>
> so the data structure is
>
> answers_list[answer] = attach_list
>
>
> Inside the template I actually can read the answers:
>
> {% for answer in answers_list.keys %}
> #use the answer object
>
> # answer_list.answer returns a attach list, right?
No.
> {% for attach in answer_list.answer %}
This is retrieving the attribute called "answer" on the answer_list
template variable (and failing silently when that attribute turns out
not to exist). It is not looking up the attribute whose name is stored
in the "answer" template variable, which is what you are expecting to
happen, based on your question. Django's templating language doesn't
work like that (specifically, you cannot do indirect variable
references).
In your particular case, the easiest solution would probably be to
retrieve both the key and value at the same time in the dictionary
iteration. So replace your for-loop with
{% for answer,value in answers_list.items %}
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---