2011-02-17 32 views
0

我想逃避unicode。python django escape unicode

我的Python脚本包含:

unicode_str = u'\u8fb0' 

我的模板文件包含:

{{ unicode_str|escape }} 

这导致KeyError异常。

如何转义unicode字符?

谢谢!

+0

你有完整的追溯? – 2011-02-17 04:58:50

回答

-2

内置转义筛选器不是为处理Unicode而设计的。写你自己的。

+0

你能指点我到哪个地方,至少给我一个怎么做的例子吗? – Albert 2011-02-18 02:01:38

0

在你的Python代码,你可以使用下面的逃跑的unicode传递一个对象作为一个整体时:

import json 
dict = {'name': 'John Doe'} 
json.dumps(dict)