flask render_template返回字符串的ASCII码 [英] flask render_template return ascii code for string
本文介绍了flask render_template返回字符串的ASCII码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
"test.html"的内容为
The content of "test.html" is
{{data}}
当我使用渲染时
render_template('test.html',data=u'{"a":12,"b":34}')
结果是
{& #34;a& #34;:12,& #34;b& #34;:34} //I add whitespace between & and # for display
当我使用
render_template_string('{{data}}',data=u'{"a":12,"b":34}')
结果是
{"a":12,"b":34}
用JavaScript中的JSON.parse()
处理第一个结果字符串很困难.那是烧瓶的虫子吗?还是我以错误的方式处理它?</p>
It's difficult to deal with the 1st result string with JSON.parse()
in JavaScript. Is that a bug of flask? Or did I deal with it in a wrong way?
推荐答案
调用render_template
时,Jinja会自动转义该字符串.要停止此操作,请使用safe
过滤器:
When you call render_template
, Jinja automatically escapes the string. To stop that, use the safe
filter:
{{ data|safe }}
这篇关于flask render_template返回字符串的ASCII码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文