这是我第一次使用 django rest 和 Django Oauth 工具包 我正在关注这个教程 oauth2-with-django-rest-framework 但是当我运行 python manage.py migrate 时出现以下错误:
导入错误:无法为 API 设置“DEFAULT_AUTHENTICATION_CLASSES”导入“oauth2_provider.ext.rest_framework.OAuth2Authentication”。导入错误:没有名为 ext.rest_framework 的模块。
出了什么问题?我还应该安装另一个模块吗? 我的虚拟环境包含:
证书==2017.4.17
夏代==3.0.4
Django==1.11.2
django 扩展==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
请求==2.18.1
六==1.10.0
Unicode==0.4.21
urllib3==1.21.1
最佳答案
它看起来像oath2_provider.ext
has been moved到oauth_provider.contrib
。您可以尝试安装旧版本的 django-oauth-toolkit
,或者尝试更改 DEFAULT_AUTHENTICATION_CLASSES
中的值:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
至:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
请注意,该教程已有几年历史,您可能会发现其他类似的问题。
关于django - 无法为 API 设置 'oauth2_provider.ext.rest_framework.OAuth2Authentication' 导入 'DEFAULT_AUTHENTICATION_CLASSES',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45029183/