需要在django模板标签中做算术运算

need to do arithmetic operations in django templates tags

我正在尝试在 Django 模板中添加三个变量。

<p>{{s.a}}+{{s.b}}+{{s.c}}</p>

但它没有做加法。如何在不使用 jquery.

的情况下添加此树变量并显示最终结果

使用 add 模板过滤器:

<p>{{ s.a|add:s.b|add:s.c }}</p>

我认为最好在 views.py 中进行计算,然后通过渲染或 render_to_response

传递它们
def something(request): 
    value = your arithmetic...
    return render(request, "template names", {'value': value})