django - 无法为 API 设置 'oauth2_provider.ext.rest_framework.OAuth2Authentication' 导入 'DEFAULT_AUTHENTICATION_CLASSES'

标签 django oauth-2.0 django-rest-framework importerror django-oauth

这是我第一次使用 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 movedoauth_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/

相关文章:

django - 从 Angular 前端在 Django Rest Framework 3.0 中保存上传的文件时出现问题

Django:自定义中间件被调用两次

java - 通过OAuth2、Spring授权后无法获取UserInfo

django - 开始 : Job failed to start UWSGI,

c# - 谷歌驱动示例 : oauth2callback not found

oauth-2.0 - 我们可以使用 ID Token 作为访问 token 吗?

python - 使用名为 "pk"的 URL 关键字参数调用预期 View

django - 如何通过 DRF 返回自定义状态码?

python - 使用 django-import-export 反向外键

python - Heroku 的 Procfile 的正确目录