Reputation: 41
{% with a=pro_details.product_quantity|add:product_details.product_quantity %}
I need to add two variables in django templates using with and add.
Upvotes: 2
Views: 7984
Reputation: 1200
You can use custom template tags for this to achieve.
The templatetags/custom_tags.py file:
from django import template
register = template.Library()
@register.simple_tag
def add(a, b):
return a+b
The template part, with our tag call:
{% load video_tags %}
(where you want to use)
{% add 5 6 %}
you can consult to this link as well. https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/
Upvotes: 7