jnns
jnns

Reputation: 5634

Access a model's field by another field's value in a template in Django?

I don't really know how to describe what I'm aiming at (EDIT: I want a dynamic attribute lookup), but I'm trying to do something like this <p>{{dict.{{object.field}}}}</p> in a template. I also tried:

{% with object.field as field %}
     {{dict.field}}
{% endwith %}

which didn't work either. Do you know how to tackle this properly?

Upvotes: 0

Views: 127

Answers (2)

Cat Plus Plus
Cat Plus Plus

Reputation: 129764

See this SO question.

Upvotes: 1

markmywords
markmywords

Reputation: 663

To loop through a dictionary you use "for":

{% for dictionary.object as obj %}
    {{ obj.field }}
{% endfor %}

Upvotes: 0

Related Questions