Home > database >  I am new to JS and jinja2. I am wondering why I am getting this syntax error? The error is occurring
I am new to JS and jinja2. I am wondering why I am getting this syntax error? The error is occurring

Time:01-02


    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.

CodePudding user response:

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

var lineData = {
   labels : {{ labels | tojson }},
   // ...
}
  • Related