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

标签 python django parsing encoding hebrew

我正在尝试通过 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/

相关文章:

python - 将多维矩阵转换为一维向量

json - 从 API 结果解析 JSON

sql - Django 中的复杂排序

java - jSoup 从 <td><span> 类获取文本

objective-c - 将 Bison/Flex/Yacc 集成到 XCode 中

Python 正则表达式 sub 单个字符

python - 暂时禁用单个 Python 单元测试

python - 8 位校验和差一

python - 多次导入模块

django - 使用查询来匹配对象,然后通过外键获取关联的所有对象