Menu Close

How to do variable subtraction in Python Django templates?

Sometimes, we want to do variable subtraction in Python Django templates.

In this article, we’ll look at how to do variable subtraction in Python Django templates.

How to do variable subtraction in Python Django templates?

To do variable subtraction in Python Django templates, we can use the add filter.

For instance, we write

{{ myval|add:"-5" }}

to add -5 to myval by using the add filter with '-5' in the curly braces.

Conclusion

To do variable subtraction in Python Django templates, we can use the add filter.

Posted in Python, Python Answers