Variable subtraction in django templates

aemdy picture aemdy · Mar 30, 2012 · Viewed 54.7k times · Source

It is able to write {{ myval.add:5 }}, {{ myval|add:value }} and even {{ myval|add:-5 }}.

However, I can't find out what I should type to add value * -1 like {{ myval|add:-value }}. This doesn't work, sadly.

Answer

Simeon Visser picture Simeon Visser · Mar 30, 2012

You need to use double quotes:

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

This subtracts five from myval.