[英]Python django escape unicode
I want to escape unicode. 我想逃脱unicode。
My python script contains: 我的python脚本包含:
unicode_str = u'\u8fb0'
My template file contains: 我的模板文件包含:
{{ unicode_str|escape }}
It results in a KeyError. 结果为KeyError。
How do I escape unicode characters? 如何转义unicode字符?
Thanks! 谢谢!
In your python code you can use the following to escape unicode when passing an object as a whole: 在您的python代码中,当整体传递对象时,可以使用以下代码转义unicode:
import json
dict = {'name': 'John Doe'}
json.dumps(dict)
The inbuilt escape filter is not designed to handle Unicode. 内置的转义过滤器不适用于处理Unicode。 Write your own.
自己写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.