【发布时间】:2012-11-06 00:40:01
【问题描述】:
我来自这个问题Use variable as dictionary key in Django template
我已经在我的视图中创建了这个上下文:
{'cats': {'LIST1': ['a','b','c'], 'LIST2': ['aa','bb','cc','dd'], 'LIST3': ['f','g']}}
我想要做的是打印列表标题,然后是所有项目,比如
LIST1:
- a
- b
- c
对于所有列表,所以我在我的模板中这样做了
{% for l_name, l in cats %}
{{ l_name }}
{%for lv in l %}
{{ lv }}
{% endfor %}
{% endfor %}
这只打印列表名称,而不打印列表。哪里错了?
谢谢
【问题讨论】:
-
使用
{{ l[lv] }}而不是{{ lv }}? -
嗯,我认为我不能在模板中使用 []。反正我发现了问题。我需要用 () 而不是 {} 创建 touple
标签: django templates django-templates