我想知道,这有什么不对:
{% for x in [1, 2, 3] %}
<p>{{x}}</p>
{% endfor %}
错误:
'for' statements should use the format 'for x in y': for x in [1, 2, 3]
更新
# .py
data = {'key1': .... //dictionary, 'key2': .... // dictionary }
# template
{% for k, v in data['key1'].items %}
<p>{{ k }}</p>
{% endfor %}
错误:
Could not parse the remainder: '['key1'].items' from 'data['key1'].items'
答案 0 :(得分:1)
Django模板语言不支持文字列表。要么从视图中传入,要么在字符串上使用make_list
过滤器:
{% for x in "123"|make_list %}