开发者

Python django escape unicode

开发者 https://www.devze.com 2023-02-11 04:05 出处:网络
I want to escape unicode. My python s开发者_开发知识库cript contains: unicode_str = u\'\\u8fb0\'

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

精彩评论

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