python - How do I read a nested dictionary in a Django template? - Stack Overflow
Mon Feb 01 2021 12:32:26 GMT+0000 (Coordinated Universal Time)
Saved by
@le_wiseman
grades_dict = {'Math': {'grade': 78, 'grade_date': '2016-05-15'},
'Reading': {'grade': 83, 'grade_date': '2016-08-16'},
'Science': {'grade': 98, 'grade_date': '2016-08-16'},
'Social Studies': {'grade': 62, 'grade_date': '2016-05-15'}}
in django template html
{% for key, value in grades_dict.items %}
<p>Grade for {{key}}: {{value.grade}}. </p>
<p>Last entered on {{value.most_recent_grade_date}}</p>
{% endfor %}
results in
Grade for Social Studies: 62.
Last entered on 2016-05-15
Grade for Science: 98.
Last entered on 2016-08-16
Grade for Reading: 83.
Last entered on 2016-08-16
Grade for Math: 78.
Last entered on 2016-05-15
content_copyCOPY
https://stackoverflow.com/questions/17097918/how-do-i-read-a-nested-dictionary-in-a-django-template
Comments