Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable subtraction in django templates

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.

like image 211
aemdy Avatar asked Mar 30 '12 17:03

aemdy


People also ask

What does {% %} mean in Django?

{% %} and {{ }} are part of Django templating language. They are used to pass the variables from views to template. {% %} is basically used when you have an expression and are called tags while {{ }} is used to simply access the variable.

What are templates in Django?

A Django template is a text document or a Python string marked-up using the Django template language. Some constructs are recognized and interpreted by the template engine. The main ones are variables and tags. A template is rendered with a context.


1 Answers

You need to use double quotes:

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

This subtracts five from myval.

like image 150
Simeon Visser Avatar answered Sep 28 '22 08:09

Simeon Visser