【发布时间】:2014-03-04 14:02:54
【问题描述】:
我正在使用 Django 模板,但遇到了嵌套字典的一个问题。
字典:
result_dict = {'type_0' : {'file_name' : 'abc', 'count' : 0},
'type_1' : {'file_name' : 'xyz', 'count' : 50}}
我的 HTML 文件中的模板是:
{% for type in result_dict %}
{{ type }}, {{ type.file_name }}
{% endfor %}
如何只显示 type_0 和 type_1 的值?
我试过了:
{% for key, value in result_dict %}
{{ key }}, {{ value }}
{% endfor %}
但它不起作用。
感谢您的帮助。
【问题讨论】:
标签: python django dictionary django-templates