我正在尝试通过 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 -*-
关于python - Django - 编写希伯来语字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26982572/