问题描述
我正在尝试在登录页面中添加社交身份验证。
为此,我已将pip install django-allauth
安装到我的项目中。
我已将所需的应用程序添加到INSTALLED_APP
,添加了AUTHENTICATION_BACKENDS
,SITE_ID
以及项目urls.py
您可以在此处查看本教程 https://django-allauth.readthedocs.io/en/latest/installation.html
问题是当我尝试迁移时会引发以下错误
ModuleNotFoundError: No module named 'allauth.socialaccountallauth'
我该如何解决。如果有人可以帮助我。
我可能会想到的一件事是我的项目中已经有一个名为accounts_app
的应用,该应用具有以下路径
path('accounts/',include('accounts_app.urls')),
并且socialauth路径为path('accounts/',include('allauth.urls')),
如果这可能是问题,那么我如何在不更改我的account_app的情况下解决它。
settings.py
"""
Django settings for camroid_project project.
Generated by 'django-admin startproject' using Django 3.1.
For more information on this file,see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values,see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
from pathlib import Path
from django.contrib.messages import constants as messages
from decouple import config
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'f@(w5t$z*7zyia!@i#(pksruu$nucw#u-f2qd#%9^g1^(*^lsx'
SECRET_KEY = config('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'camroid_app.apps.CamroidAppConfig','accounts_app.apps.AccountsAppConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.sites','allauth','allauth.account','allauth.socialaccount'
'allauth.socialaccount.providers.google',]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]
ROOT_URLCONF = 'camroid_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [os.path.join(BASE_DIR,'templates')],'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',],},]
WSGI_APPLICATION = 'camroid_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql','NAME': config('DB_NAME'),'USER': config('DB_USER'),'PASSWORD': config('DB_PASSWORD'),'HOST': config('HOST'),}
}
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend','allauth.account.auth_backends.AuthenticationBackend',]
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS,JavaScript,Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'static')
]
STATIC_ROOT = os.path.join(BASE_DIR,'assets')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
#email verification
EMAIL_BACKEND = config('EMAIL_BACKEND')
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_USE_TLS = config('EMAIL_USE_TLS',cast=bool)
EMAIL_PORT = config('EMAIL_PORT',cast=int)
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
MESSAGE_TAGS = {
messages.ERROR: 'danger',50: 'critical',}
跟踪
C:\Users\SandeepNegi\Desktop\CAMROID\camroid_project>python manage.py migrate
Traceback (most recent call last):
File "manage.py",line 22,in <module>
main()
File "manage.py",line 18,in main
execute_from_command_line(sys.argv)
File "C:\Users\SandeepNegi\.virtualenvs\CAMROID-nt7jYvBL\lib\site-packages\django\core\management\__init__.py",line 401,in execute_from_command_line
utility.execute()
File "C:\Users\SandeepNegi\.virtualenvs\CAMROID-nt7jYvBL\lib\site-packages\django\core\management\__init__.py",line 377,in execute
django.setup()
File "C:\Users\SandeepNegi\.virtualenvs\CAMROID-nt7jYvBL\lib\site-packages\django\__init__.py",line 24,in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\SandeepNegi\.virtualenvs\CAMROID-nt7jYvBL\lib\site-packages\django\apps\registry.py",line 91,in populate
app_config = AppConfig.create(entry)
File "C:\Users\SandeepNegi\.virtualenvs\CAMROID-nt7jYvBL\lib\site-packages\django\apps\config.py",line 116,in create
mod = import_module(mod_path)
File "c:\users\sandeepnegi\appdata\local\programs\python\python38-32\lib\importlib\__init__.py",line 127,in import_module
return _bootstrap._gcd_import(name[level:],package,level)
File "<frozen importlib._bootstrap>",line 1014,in _gcd_import
File "<frozen importlib._bootstrap>",line 991,in _find_and_load
File "<frozen importlib._bootstrap>",line 961,in _find_and_load_unlocked
File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_removed
File "<frozen importlib._bootstrap>",line 973,in _find_and_load_unlocked
ModuleNotFoundError: No module named 'allauth.socialaccountallauth'
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)