开发者

dictionary within other dictionary in django template

开发者 https://www.devze.com 2023-03-03 20:49 出处:网络
In a Django template, is there a way to get a value id, score and num_votes from Data Structure: { 1: {\'score\': 0,\'num_votes\': 2},

In a Django template, is there a way to get a value id, score and num_votes from Data Structure:

{
    1: {'score': 0,  'num_votes': 2}, 
    2: {'score': -1, 'num_votes': 1}, 
    3: {'score': 2,  'num_votes': 2}, 
    6: {'score': 1,  'num_votes': 1}, 
    7: {'score': 2,  'num_votes': 2}
} 

Example:

1  0  2 
2开发者_C百科 -1  1

In django template, but throws error:

{% scores_for_objects list_status as scores %}
{% for status,value in scores.items %}
{{status}}**{{value.'score'}}
{{value.'num_votes'}}**{% endfor %}


That's not how you do it.

            {{status}}**{{value.score}}{{value.num_votes}}**


Not sure if I have understood your question but try that :

{% for key1, dict in my_main_dict.items %}
  {% for sub_key, value in dict.items %}
    {{ key1 }} {{ key2 }} {{ value }} <br />
  {% endfor %}
{% endfor %}
0

精彩评论

暂无评论...
验证码 换一张
取 消