'How to loop jQuery / JavaScript in Django template

I have the following in a Django template (*.html):

{% for num in Charts %}
<div id="myChart{{forloop.counter0}}"></div>
{% endfor %}

<script>
$.get('{% url 'json0' %}', function (data) {
    blah blah blah;
    $("#mychart0").highcharts(data);   
});

$.get('{% url 'json1' %}', function (data) {
    blah blah blah;
    $("#mychart1").highcharts(data);   
});

...
...

</script>

I would like to loop the script tag in a similar way as the div tag. In particular I wish the following code would work

    {% for num in Charts %}
     <script>
            
            $.get('{% url 'json{{forloop.counter0}}' %}', function (data) {
                blah blah blah;
                $("#mychart{{forloop.counter0}}").highcharts(data);   
            });
     </script>
    {% endfor %}

What would be a correct way to achieve something similar? The above code almost works except for an error with {% url 'json{{forloop.counter0}}' %}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source