Django Allauth - ModuleNotFoundError:即使正确安装了 django-allauth,也没有名为“allauth.account.middleware”的模块

问题描述 投票:0回答:1

“ModuleNotFoundError:没有名为“allauth.account.middleware”的模块”

即使 django-allauth 已全部安装和设置,我仍然在 django 项目中收到此错误???

我什至尝试重新安装并将我的 python 更改为 python3,但没有更改任何内容,无法弄清楚为什么所有其他导入都可以工作,但中间件除外......

请帮忙?

设置.py:

"""
Django settings for youtube2blog2 project.

Generated by 'django-admin startproject' using Django 4.2.4.

For more information on this file, see

For the full list of settings and their values, see
"""

from pathlib import Path
import django
import os
import logging
import pyfiglet

import allauth

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'omegalul'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# CUSTOM CODE

# os.environ['FFMPEG_PATH'] = '/third-party/ffmpeg.exe'
# os.environ['FFPROBE_PATH'] = '/third-party/ffplay.exe'

OFFLINE_VERSION = False

def offline_version_setup(databases):
    if (OFFLINE_VERSION):

        # WRITE CODE TO REPLACE DATABASES DICT DATA FOR OFFLINE SETUP HERE

        return True
    return

banner_ascii_art = pyfiglet.figlet_format("CHRIST IS KING ENTERPRISES")

logger = logging.getLogger()

logger.setLevel(logging.DEBUG)

print("\n - CURRENT DJANGO VERSION: " + str(django.get_version()))

print("\n - settings.py: Current logger level is " + str(logger.getEffectiveLevel()))
logger.debug('settings.py: Logger is working.\n\n')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

AUTHENTICATION_BACKENDS = [
    
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',

    # `allauth` specific authentication methods, such as login by email
    'allauth.account.auth_backends.AuthenticationBackend',
    
]

'''

NEEDED SETUP FOR SOCIAL AUTH

REQUIRES DEVELOPER CREDENTIALS

ON PAUSE UNTIL MVP IS DONE

# Provider specific settings
SOCIALACCOUNT_PROVIDERS = {
    'google': {
        # For each OAuth based provider, either add a ``SocialApp``
        # (``socialaccount`` app) containing the required client
        # credentials, or list them here:
        'APP': {
            'client_id': '123',
            'secret': '456',
            'key': ''
        }
    }
    'apple': {
        
    }
    'discord' {

    }
}
'''
LOGIN_REDIRECT_URL = 'dashboard'

#

# Application definition

INSTALLED_APPS = [

    # My Apps
    'yt2b2',
    'home',
    'dashboard',

    # Django Apps

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Downloaded Apps
    'rest_framework',
    'embed_video',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    #'allauth.socialaccount.providers.google',
    #'allauth.socialaccount.providers.apple',
    #'allauth.socialaccount.providers.discord',
]

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',

    # Downloaded Middleware
    'allauth.account.middleware.AccountMiddleware',
]

ROOT_URLCONF = 'youtube2blog2.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 = 'youtube2blog2.wsgi.application'


# Database

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3', # <--------- OFFLINE VERSION

        # Consider masking these secret variables using a .env file to beef up your Django app's security. Besides, Vercel allows you to list your environment variables during deployment.
        
        #'URL' : 'postgresql://postgres:oibkk5LL9sI5dzY5PAnj@containers-us-west-128.railway.app:5968/railway',
        #'NAME' : 'railway',
        #'USER' : 'postgres',
        #'PASSWORD' : 'oibkk5LL9sI5dzY5PAnj',
        #'HOST' : 'containers-us-west-128.railway.app',
        #'PORT' : '5968'
    }
}

# Password validation

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)

STATIC_URL = '/static/' # the path in url

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

尝试更改为 python3,通过 pip 重新安装 django-allauth,其他 stackoverflow 解决方案,通过 allauth 文档进行转换...到目前为止没有任何效果

更新:由于垃圾邮件过滤器而删除了 https 链接

错误位置:

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',

# Downloaded Middleware
'allauth.account.middleware.AccountMiddleware',

]

python python-3.x django django-allauth django-settings
1个回答
0
投票

中间件仅存在于未发布的 0.56.0-dev 中,您可能正在使用 0.55.2 并遵循 0.56 文档。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.