Flask Render_template Return Ascii Code For String
The content of 'test.html' is {{data}} When I render it using render_template('test.html',data=u'{'a':12,'b':34}') the result is {& #34;a& #34;:12,& #34;b& #34;:3
Solution 1:
When you call render_template
, Jinja automatically escapes the string. To stop that, use the safe
filter:
{{ data|safe }}
Solution 2:
The issue is that when loading from the file the values will be escaped, and this is expected. What I'd recommend, however, is that if you are looking to return JSON do the following instead, as an example:
from flask import jsonify
@app.route('/get_data')defget_data():
return jsonify({"a":12,"b":34})
http://flask.pocoo.org/docs/0.10/api/#flask.json.jsonify
Post a Comment for "Flask Render_template Return Ascii Code For String"