我需要简化这个 Django 模板,
{{ var.1 }}
{{ var.2 }}
{{ var.3 }}
{{ var.4 }}
{{ var.5 }}
var 是作为上下文传递给模板的 Python 列表
如何使用 for 标签结构转换上述模板。 我试过这个,但没有工作。
{% for i in var|length %}
{{ var.i }}
{% endfor %}
你可以做
{% for x in var %}
{{x}}
{% endfor %}