【问题标题】:How to ADD for loop result in templates如何在模板中添加 for 循环结果
【发布时间】:2022-01-25 18:54:58
【问题描述】:

views.html

{% for products in product %}
<tr>
    <td>{{ products.quantity_deliver1 }}</td>
    <td>{{ products.quantity_deliver2 }}</td>
    <td>{{ Code Here }}</td>

</tr>
{% empty %}
<tr>
    <td colspan="3" class="text-center bg-warning">No Products</td>
</tr>
{% endfor %}

如何添加products.quantity_deliver1 + products.quantity_deliver2 并在第三个数据单元格中输出总和。

【问题讨论】:

    标签: django django-views django-templates


    【解决方案1】:

    您可以使用内置的 django 模板标签 add 添加两个。

    {{products.quantity_deliver1|add:products.quantity_deliver2}}
    

    参考 - https://docs.djangoproject.com/en/dev/ref/templates/builtins/#add

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-08-02
      • 1970-01-01
      • 2018-06-13
      • 1970-01-01
      • 2013-10-26
      相关资源
      最近更新 更多