How to do math in a Django template?

Tommy picture Tommy · Jun 8, 2011 · Viewed 95.9k times · Source

I want to do this:

100 - {{ object.article.rating_score }} 

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

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

Answer

Daniel Roseman picture Daniel Roseman · Jun 8, 2011

You can use the add filter:

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