Django OAuth Toolkit:无法导入ext.rest_framework

fd.*_*nov 3 django oauth-2.0 django-rest-framework django-oauth

我正在尝试为我的Django REST API设置OAuth2身份验证系统(使用DjangoRestFramework和Django-Oauth-Toolkit).我根据官方文档写了一切,但是系统给出错误"无法导入ext.rest_framework"

这是我的setting.py文件:

OAUTH2_PROVIDER = {
    # this is the list of available scopes
    'SCOPES': {'read': 'Read scope', 'write': 'Write scope', 'groups': 'Access to your groups'}
}


REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'oauth2_provider.ext.rest_framework.OAuth2Authentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
    'PAGE_SIZE': 10
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

fd.*_*nov 6

好的,我检查了源代码oauth2_provider.显然他们改变了结构,但没有在他们的网站上更新教程.所以,oauth2_provider.ext包不再存在,你应该使用oauth2_provider.contrib.也就是说,以下代码工作正常:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'PAGE_SIZE': 10
}
Run Code Online (Sandbox Code Playgroud)