【问题标题】:Custom Templatetags not working properly自定义模板标签无法正常工作
【发布时间】: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。这将使用数据为您呈现模板。

标签: django django-templates


【解决方案1】:

感谢那些花时间尝试回答的人,但这完全是我的错。似乎这是我的一些缓存问题。

道歉。

【讨论】:

    猜你喜欢
    • 2014-06-10
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2019-11-16
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多