【发布时间】:2011-06-28 20:12:54
【问题描述】:
我想转义 unicode。
我的 python 脚本包含:
unicode_str = u'\u8fb0'
我的模板文件包含:
{{ unicode_str|escape }}
这会导致 KeyError。
如何转义 unicode 字符?
谢谢!
【问题讨论】:
-
你有完整的回溯吗?
标签: python django unicode django-templates
我想转义 unicode。
我的 python 脚本包含:
unicode_str = u'\u8fb0'
我的模板文件包含:
{{ unicode_str|escape }}
这会导致 KeyError。
如何转义 unicode 字符?
谢谢!
【问题讨论】:
标签: python django unicode django-templates
在您的 python 代码中,您可以在传递整个对象时使用以下代码来转义 unicode:
import json
dict = {'name': 'John Doe'}
json.dumps(dict)
【讨论】:
内置的转义过滤器不是为处理 Unicode 而设计的。自己写。
【讨论】: