Wagh
Wagh

Reputation: 4306

need to do arithmetic operations in django templates tags

I am trying to add three variables in django templates.

<p>{{s.a}}+{{s.b}}+{{s.c}}</p>

but its not doing the addition. how to do the addition of this tree variables and display final result without using jquery.

Upvotes: 1

Views: 752

Answers (2)

atkawa7
atkawa7

Reputation: 471

I think it is better if you do your calculations in your views.py then pass them through render or render_to_response

def something(request): 
    value = your arithmetic...
    return render(request, "template names", {'value': value})

Upvotes: 1

catavaran
catavaran

Reputation: 45575

Use the add template filter:

<p>{{ s.a|add:s.b|add:s.c }}</p>

Upvotes: 2

Related Questions