【发布时间】:2017-07-12 08:29:19
【问题描述】:
我正在尝试将数据发送到名为 order_details 的 TemplateTags。此模板标签在数据库中查找信息,然后渲染信息列表调用另一个模板。当我在返回之前打印时,我的 html 出现在日志文件中。但是渲染的页面中什么都没有显示。
@register.filter
def order_details(data):
params = EParamCmd.objects.filter(command=data.id, default=False)
dictfunction = {}
for p in params:
if p.param.typ == 'function':
dictfunction[p.param.name_inf] = CustomFunction.objects.get(name_inf=p.value)
t = get_template('Formulaire/order-details-params.html')
c = {'params': params, 'func': dictfunction}
LOG.info(t.render(c))
return str(t.render(c))
LOG.info 显示应在此模板中显示的 html:
{% load tags %}
<h4>Liste des paramètres :</h4>
{{order|order_details}}
当我在模板标签中返回“Hello”时,它会显示出来。
谢谢。
【问题讨论】:
-
您应该显示 order-details-params.html 的内容。但是,这不是过滤器的工作,而是模板标签的工作 - 具体来说,inclusion tag。这将使用数据为您呈现模板。