Skip to main content
 首页 » 编程设计

python之Django之编写希伯来语字符串

2024年10月25日2452php

我正在尝试通过 Django 代码中的解析 rest API 发送希伯来语字符串 代码没问题——用英文发送字符串效果很好 当字母是希伯来语时,我收到以下错误:

Non-ASCII character '\xd7' but no encoding declared; 

如何以编程方式为特定行设置编码?

请您参考如下方法:

在 docs 中有解释:

Python supports writing Unicode literals in any encoding, but you have to declare the encoding being used. This is done by including a special comment as either the first or second line of the source file

在你的情况下:

# -*- coding: utf-8 -*-