【发布时间】:2011-01-10 17:48:05
【问题描述】:
我不想遍历字典。我有一个键,并且只想返回该键的值(如果存在)。
我没有得到任何结果。
users // a dictionary of user_ids and values
user.key // a user id.
{{ users.user.key }}
当我知道传递的键的值存在时,这不会显示任何内容。
【问题讨论】:
标签: python django templates dictionary
我不想遍历字典。我有一个键,并且只想返回该键的值(如果存在)。
我没有得到任何结果。
users // a dictionary of user_ids and values
user.key // a user id.
{{ users.user.key }}
当我知道传递的键的值存在时,这不会显示任何内容。
【问题讨论】:
标签: python django templates dictionary
问题是Django将users.user.key解释为users.user[key],这当然不是你想要的。
您可以使用with 指令来解决此问题。
{% with user.key as user_key %}
{{users.user_key}}
{% endwith %}
【讨论】: