我正在使用 python、graphene 和 django 实现 graphql 解决方案,但出现以下导入错误:
Result: Failure Exception: ImportError: cannot import name 'force_text' from 'django.utils.encoding'
"/home/site/wwwroot/.python_packages/lib/site-packages/graphene_django/utils/utils.py", line 6, in <module> from django.utils.encoding import force_text
我不确定版本以及是否需要导入其他模块。我的 requirements.txt 是这样的:
graphene>=2.1,<3
graphene-django>=2.1,<3
graphql-core>=2.1,<3
graphql-relay==2.0.1
django-filter>=2
有人有类似的问题并且可以查看我使用的版本吗?谢谢
原文由 Gerd 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 Django 4.0 中我们没有
force_text
https://docs.djangoproject.com/en/4.0/ref/utils/#module-django.utils.encoding
而是将
force_text
更改为force_str
Linux:
YOUR_VENV/lib/PYTHON_VERSION/site-packages/graphene_django/utils/utils.py
视窗:
YOUR_VENV/lib/site-packages/graphene_django/utils/utils.py
至
和
至