Can I access specific key values in dictionary from django template?

后端 未结 6 1385
独厮守ぢ
独厮守ぢ 2021-01-05 16:20

Is there any get() function for this instead?

{% for key, value in choices.items %} 
  
  • {{key}} - {{value}}
  • {% endfor %}
    <
    6条回答
    •  北荒
      北荒 (楼主)
      2021-01-05 17:09

      If you want a specific value, just add it to the dotted-path:

      {{ choices.items.somekey }}
      

      will get you the value of choices.items['somekey'] if choices.items is a dict.

    提交回复
    热议问题