开发者

Python django escape unicode

I want to escape unicode.

My python s开发者_开发知识库cript contains:

unicode_str = u'\u8fb0'

My template file contains:

{{ unicode_str|escape }}

It results in a KeyError.

How do I escape unicode characters?

Thanks!


In your python code you can use the following to escape unicode when passing an object as a whole:

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


The inbuilt escape filter is not designed to handle Unicode. Write your own.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜