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

后端 未结 6 1436
独厮守ぢ
独厮守ぢ 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

      You can use {{ choices.items.key }} to access a specific dict element.

      There is no reason to care about whitespace in the HTML code though; the typical end-user has no real business in reading it and if he's curious he an always use a DOM viewer or run it through a HTML beautifier.

    提交回复
    热议问题