【问题标题】:what is the jinja2 equivalent of django add filter?什么是 jinja2 相当于 django 添加过滤器?
【发布时间】:2020-09-23 09:33:19
【问题描述】:

我正在尝试在 jinja2 中呈现如下所示的 html

<div>
     <tr>
        <td>{{ row.a|add:b}}</td>
     </tr>
</div>

它会抛出错误 expected token 'end of print statement', got ':' 。上面的 html 是为 django 模板语言编写的。有人可以帮我找到 jinja2 的正确替代品吗?

【问题讨论】:

    标签: python html django-templates jinja2


    【解决方案1】:

    您可以在 jinja2 中使用sum 过滤器
    在您的情况下,[a,b]|sum 应该可以工作

    检查这个:https://jinja.palletsprojects.com/en/2.11.x/templates/#sum

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 2012-09-18
      • 1970-01-01
      • 2017-04-02
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      相关资源
      最近更新 更多