无法加载 WSGI 应用程序“mysite.wsgi.application”;导入模块时出错

我使用 django 3.1.1 和 Python 3.8.5。我想创建简单的博客。我使用一些旧代码,其中程序员可能使用 django 1.11,所以我改变了很多东西,但现在我陷入困境


我收到错误


    raise ImproperlyConfigured(

django.core.exceptions.ImproperlyConfigured: WSGI application 'mysite.wsgi.application' could not be loaded; Error importing module.


当我尝试删除时


WSGI_APPLICATION = 'mysite.wsgi.application'


我收到一个错误


ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class

这是我的整个设置.py


"""

Django settings for mysite project.


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


For more information on this file, see

https://docs.djangoproject.com/en/1.8/topics/settings/


For the full list of settings and their values, see

https://docs.djangoproject.com/en/1.8/ref/settings/

"""


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

import os


BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



# Quick-start development settings - unsuitable for production

# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/


# SECURITY WARNING: keep the secret key used in production secret!

SECRET_KEY = '*s@w*wx_w23k5vp%c%*aatqr42dsu3m$^(et@a(yrx$(4j-u*o'


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

DEBUG = True


ALLOWED_HOSTS = []


SITE_ID = 1


# Application definition


INSTALLED_APPS = (

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'django.contrib.sites',

    'django.contrib.sitemaps',

    'blog',

    'taggit',

    'haystack',

)


繁星coding
浏览 183回答 2
2回答

摇曳的蔷薇

某些中间件已过时或已移动/重命名。尝试使用 django 3 中的默认中间件列表: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',]

泛舟湖上清波郎朗

我得到了同样的错误:django.core.exceptions.ImproperlyConfigured:无法加载 WSGI 应用程序“core.wsgi.application”;导入模块时出错。当我将项目中未安装的包“hello”MIDDLEWARE添加到中时settings.py:MIDDLEWARE = [&nbsp; &nbsp; 'django.middleware.security.SecurityMiddleware',&nbsp; &nbsp; 'django.contrib.sessions.middleware.SessionMiddleware',&nbsp; &nbsp; 'corsheaders.middleware.CorsMiddleware',&nbsp; &nbsp; 'django.middleware.common.CommonMiddleware',&nbsp; &nbsp; 'django.middleware.csrf.CsrfViewMiddleware',&nbsp; &nbsp; 'django.contrib.auth.middleware.AuthenticationMiddleware',&nbsp; &nbsp; 'django.contrib.messages.middleware.MessageMiddleware',&nbsp; &nbsp; 'django.middleware.clickjacking.XFrameOptionsMiddleware',&nbsp; &nbsp; 'hello', # 'hello' package doesn't exist]MIDDLEWARE因此,在将它们添加到以下位置之前,不要忘记安装所需的软件包settings.py:pip install <package>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python