Django Google 在 /auth/complete/google-oauth2/ 登录 ModuleNotFoundError

Django Google Sign in ModuleNotFoundError at /auth/complete/google-oauth2/

我正在尝试在 Django 登录中使用 google 创建登录,所以当我创建 'Login with Google' 时,它会转到 google 登录页面,但在选择 Google 帐户时显示错误,

ModuleNotFoundError at /auth/complete/google-oauth2/
No module named 'social'

我的项目urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('', include('pages.urls')),
    path('accounts/', include('django.contrib.auth.urls')),
    path('auth/', include(('social_django.urls', 'social_django'), namespace='social')),
    path('admin/', admin.site.urls),
]

settings.py

import os

INSTALLED_APPS = [
    #...,
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'social_django',
    'django',
]

MIDDLEWARE = [
    #...
    #...
]

ROOT_URLCONF = 'trydjango.urls'

TEMPLATES = [
    {
        'BACKEND': '# ...',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',  # Google login
                'social_django.context_processors.login_redirect',  # Google Login
            ],
        },
    },
]

DATABASES = {
    'default': {
        # ...
        # ...
    }
}

AUTH_PASSWORD_VALIDATORS = [
   # ....
]

AUTHENTICATION_BACKENDS = (
 'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
 'social_core.backends.google.GoogleOpenId',  # for Google authentication
 'social_core.backends.google.GoogleOAuth2',  # for Google authentication
 'social_core.backends.google.GoogleOAuth',
 # 'social_core.backends.github.GithubOAuth2',  # for Github authentication
 # 'social_core.backends.facebook.FacebookOAuth2',  # for Facebook authentication

 'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.debug.debug',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
    'social.pipeline.debug.debug',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]
# Google+ SignIn (google-plus)
SOCIAL_AUTH_GOOGLE_PLUS_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_PLUS_SCOPE = [
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]


SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '*************************.....'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '************************' 

以下是错误的更多描述:

Django Version: 2.1
Exception Type: ModuleNotFoundError
Exception Value: No module named 'social'
Exception Location: /home/barmansvaps/anaconda3/lib/python3.6/site-packages/social_core/utils.py in import_module, line 52
Python Executable: /home/barmansvaps/anaconda3/bin/python3

你有没有安装python-social-auth模块。请试试这个代码

pip install python-social-auth

您可以阅读更多相关信息 here

更新: 正如 omab 所建议的。请避免使用未维护的过时库,并使用当前维护的库,如 social_core