Django templates: how do I use key to access value?
I don't want to iterate through the dictionary. I have a key, and simply want to return the value for that key if it exists.
I'm not getting any results.
users // a dictionary of user_ids and values
user.key // a user id.
{{ users.user.key }}
This displays nothing when I know the value for the key passed exists.
The problem is that Django interprets users.user.key
as users.user[key]
, which of course is not what you want.
You can use with
directive to work around this.
{% with user.key as user_key %}
{{users.user_key}}
{% endwith %}
精彩评论