JavaScript raises SyntaxError with data rendered in Jinja template

后端 未结 3 1189
无人共我
无人共我 2020-11-21 13:57

I am trying to pass data as JSON from a Flask route to a Jinja template rendering JavaScript. I want to iterate over the data using JavaScript. The browser shows Syn

3条回答
  •  鱼传尺愫
    2020-11-21 14:14

    The problem is that your server returns not JSON, but rendered HTML, which escapes some of the symbols with & notation.

    Instead of using

    return render_template("folder.html", data=tree)
    

    try

    return flask.jsonify(**tree)
    

提交回复
热议问题