【发布时间】:2017-02-04 22:37:28
【问题描述】:
寻找一种解决方案来读取可以传递到上下文并在模板中显示的完整变量列表,使用 Django 或 Jinja2。
例如,在 Django 中是这样的:
from django.template import Template
template = Template("<h1>{{title}}</h1>{%for v in values%}<p>{{v}}</p>{%endfor%}")
for node in template.nodelist:
#Get the variable name from the node
这似乎是一种真正的痛苦。我想要的只是一个上下文对象可以传递给模板的键列表,在这个例子中是“title”和“values”
【问题讨论】: