无法导入'rest_framework.authentication.OAuth2Authentication'

时间:2016-05-15 05:03:22

标签: python django oauth-2.0

我是Django的新手。我想在django中设置OAuth,我收到了这个错误。

enter image description here

我的setting.py是这样的。我需要安装什么东西吗?

REST_FRAMEWORK = {    
    'DEFAULT_AUTHENTICATION_CLASSES':
        ('rest_framework.authentication.OAuth2Authentication',
         'rest_framework.authentication.SessionAuthentication'),

    'DEFAULT_MODEL_SERIALIZER_CLASS':
        'rest_framework.serializers.ModelSerializer',

    'DEFAULT_PERMISSION_CLASSES':
    ('rest_framework.permissions.IsAdminUser',)
}

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sessions',
    'rest_framework',
    'provider',
    'provider.oauth2',
    'todo'
)

1 个答案:

答案 0 :(得分:0)

您的设置必须如下所示:

REST_FRAMEWORK = {    
    'DEFAULT_AUTHENTICATION_CLASSES':
        ('oauth2_provider.contrib.rest_framework.OAuth2Authentication',
         'rest_framework.authentication.SessionAuthentication'),

    'DEFAULT_MODEL_SERIALIZER_CLASS':
        'rest_framework.serializers.ModelSerializer',

    'DEFAULT_PERMISSION_CLASSES':
    ('rest_framework.permissions.IsAdminUser',)
}

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sessions',
    'rest_framework',
    'oauth2_provider',
    'todo'
)