I am new to JS and jinja2. I am wondering why I am getting this syntax error? The error is occurring in the for loop

Question:


    var lineData = {
         labels : [
             {% for item in labels %}
                "{{ item }}",
             {% endfor %}
         ],

I am getting an error in the for loop. I am not sure where I am going wrong with the syntax.

Asked By: jacobsonblanton

||

Answers:

You can pass data to JavaScript within a template using the jinja filter tojson.

var lineData = {
   labels : {{ labels | tojson }},
   // ...
}
Answered By: Detlef
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.