Flask set variable is not updating value in (HTML)

Advertisements

I’m trying to change the position of a svg tag, after every svg is created inside a bucle, but my variable x_value_weeks is not updating inside my loop, and it just stays with the same value.

I declare my variable

{% set x_value_weeks = 5 %}

I set the variable outside the bucle and inside the bucle I update it using

{% set x_value_weeks = x_value_weeks + 10 %}

full code

<svg class="user-streak-svg-container" xmlns="http://www.w3.org/2000/svg">
    {% set x_value_weeks = 5 %}
    {% for week in weeks %}
        <svg class="user-streak-svg-column" x="{{ x_value_weeks }}">
           ....
        </svg>
        {% set x_value_weeks = x_value_weeks + 10 %}
    {% endfor %}
</svg>

>Solution :

Try this:

<svg class="user-streak-svg-container" xmlns="http://www.w3.org/2000/svg">
    {% for week in range(100) %}
        <svg class="user-streak-svg-column" x="{{ 5 + week * 10 }}">
           <!-- Your SVG content here -->
        </svg>
    {% endfor %}
</svg>

x="{{ 5 + week * 10 }}" calculates the x position dynamically for each iteration in the loop.

Leave a ReplyCancel reply