Django OAuth 工具包:无法导入 ext.rest_framework
Django OAuth Toolkit: could not import ext.rest_framework
我正在尝试为我的 Django REST API 设置 OAuth2 身份验证系统(使用 DjangoRestFramework 和 Django-Oauth-Toolkit)。
我是按照官方文档写的,但是系统报错"could not import 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
}
谢谢!
好的,我检查了 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
}
我正在尝试为我的 Django REST API 设置 OAuth2 身份验证系统(使用 DjangoRestFramework 和 Django-Oauth-Toolkit)。 我是按照官方文档写的,但是系统报错"could not import 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
}
谢谢!
好的,我检查了 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
}