How to do math in a Django template?

后端 未结 3 825
傲寒
傲寒 2020-12-13 02:08

I want to do this:

100 - {{ object.article.rating_score }} 

So for example, the output would be 20 if {{ object.article.

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 02:27

    Use django-mathfilters. In addition to the built-in add filter, it provides filters to subtract, multiply, divide, and take the absolute value.

    For the specific example above, you would use {{ 100|sub:object.article.rating_score }}.

提交回复
热议问题