I am trying to use Django for loop in JavaScript but I am getting a syntax error:
<script>
var config = {
type: 'pie',
data: {
datasets: [{
data: [1780000, 1630000],
backgroundColor: [
'#ff0000', '#0000ff', '#ff0080', '#73ffff', '#5c26ff', '#002db3', '#ffff26', '#4cff4c', '#ff00ff'
],
label: 'Population'
}],
labels: [{% for label in labels %} {{ label }}, {% endfor %}]
},
options: {
responsive: true
}
};
</script>
this part is what i a have a problem with to be exact
{% for label in labels %} {{ label }}, {% endfor %}
just typing:
{% for %}
gives me a syntax error I looked at similar stack overflow questions and they just use the for loop normally without any problems so why am I getting a syntax error. I even tried it in an an empty Js file and still get a syntax error. Am I forgetting to import something? It works just fine in the HTML file.