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.
精彩评论