【发布时间】:2016-11-03 05:38:51
【问题描述】:
我有一个基本模板:
base.html:
{% for object in object_list %}
{%block object_attributes%} {%endblock%}
{% endfor %}
还有一个继承它的孩子:
child.html
{% extends "base.html" %}
{%block object_attributes%}
{{block.super}}
<td>{{ object.name }}</td>
<td>{{ object.address }}</td>
{%endblock%}
然而,孩子似乎无法看到变量“object”。我知道它是 for 循环的局部变量,但我怎样才能让它对孩子可见?
【问题讨论】:
-
因为循环中有其他东西我没有写在这里,在许多模板之间重复。
-
你可以考虑为此写一个上下文处理器
标签: django python-2.7 django-templates