Jinja autoescapes potentially unsafe characters (such as quotes) to avoid security issues. You need to tell it that the data you are rendering is safe, either by using the |safe
filter in the template or wrapping it in Markup
in the view. You can also use the |tojson
filter rather than parsing and marking the JSON manually.
Use Markup
to mark it safe from the view.
from markupsafe import Markup
render_template('index.html', piedata=Markup(json.dumps(pieData)))
Or mark it safe in the template.
{{ piedata|safe }}
Preferably, just convert it in the template without calling json.dumps
in the view. Older versions of Flask required calling |tojson|safe
, but the |safe
is no longer needed.
{{ piedata|tojson }}