[Answer]-How to add two django variables in a django template

1πŸ‘

βœ…

{% with saving=rec.max_saving|slugify %}

{% with name=rec.category|add:’_’|add:rec.max_saving %}

{{ name }}

{% endwith %}
{% endwith %}

This issue I was facing was due to the two variables being of different datatype’s.
Using slugify i converted the int variable to string.

Slugify worked for me because there was no spaces in my max_saving variable.
Ideally one should use stringformat:”s” for django styled string conversion.

πŸ‘€gunj_desai

0πŸ‘

try this…

{% with rec.category|add:'_'|add:rec.max_saving as name %}
{{ name }}
{% endwith %}

πŸ‘€Shivratna

Leave a comment