[Fixed]-How to change the value of a django variable

1👍

You can achieve this with a for loop:

{% with "product" as name %}
    {% for i in products.count %}
        <div>{{name}}{{ forloop.counter }}</div> 
    {% endfor %}
{% endwith %}

Output:

<div>product1</div>

<div>product2</div>

etc.


If you want the counter to start with 0 instead of 1 you can use forloop.counter0

Leave a comment