Categories
Python Answers

How to do variable subtraction in Python Django templates?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *