Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flask set variable is not updating value in (HTML)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{% 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading