Search code examples
pythonflaskchart.jsjinja2

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



    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.


Solution

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

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