如何在Django模板中进行数学运算? [英] How to do math in a Django template?

查看:298
本文介绍了如何在Django模板中进行数学运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样做:

100 - {{ object.article.rating_score }} 

因此,例如,如果<$ c $,输出将为 20 c> {{object.article.rating_score}} 等于 80

So for example, the output would be 20 if {{ object.article.rating_score }} equaled 80.

如何我在模板级别执行此操作?我无权访问Python代码。

How do I do this at the template level? I don't have access to the Python code.

推荐答案

您可以使用 add 过滤器:

You can use the add filter:

{{ object.article.rating_score|add:"-100" }}

这篇关于如何在Django模板中进行数学运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆