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.

up vote 4 down vote accepted

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 %}
  • 2
    I'm on GAE which has Django 0.96 I think, and that's not working. Maybe I need to create a custom filter. – Will Curran Jan 10 '11 at 18:11
  • 1
    For what it is worth this does not actually look like it works for Django 1.4.x. I've been told that this is not something that is supported. If this works it must require some additional filter that is not listed as a part of this answer. – Beau Simensen Oct 30 '12 at 20:59

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.