Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 16, 2005 13:09:04

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Dictionary lookups in templates?


Hi,

I am trying to perform a dictionary lookup within a template, and have
got stuck. I pass a list( dirList ) and a dict ( thumbNames ) to
render_to_response. Within the template I process the list, and print
each occurence of dirList. What I would like to do, is display an
entry of thumbNames based on the value of dirName. Something like:

{% for dirName in dirList %}
{{ dirName }} - {{ thumbNames.{{ dirName }} }}
{% endfor %}

Is there a way of implementing something like this? I'd appreciate any
pointers.

Regards

J

Offline

#2 Nov. 16, 2005 15:20:35

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Dictionary lookups in templates?


JA wrote:What I would like to do, is display an
entry of thumbNames based on the value of dirName. Something like:

{% for dirName in dirList %}
{{ dirName }} - {{ thumbNames.{{ dirName }} }}
{% endfor %}This is not possible by design: Django tries to keep templates offbecoming a programming language. You need to prepare the resulting listin your view and then pass it to a template:Context(...{
'dirList':[thumbNames for dirName in dirList],
})

Offline

#3 Nov. 17, 2005 21:21:07

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Dictionary lookups in templates?


I'll give that a whirl, thank you.

J

Offline

#4 Nov. 18, 2005 14:21:32

J.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Dictionary lookups in templates?


Found an easier way. I can pass a list of class instances, and perform
a look on the class attributes.

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support