gpt4 book ai didi

python - Django错误: 'myproject.wsgi.application' could not be loaded

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:20 25 4
gpt4 key购买 nike

我目前正在尝试测试我的 Django 应用程序,该应用程序最终将部署到 Heroku。在本地测试时,我遇到错误:

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

我的 wgsi.py 文件配置为:

import os
import signal
import sys
import traceback
import time

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "foodForThought.settings")

application = get_wsgi_application()
application = DjangoWhiteNoise(application)

我的settings.py文件配置为:

import os

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

...

# Application definition

INSTALLED_APPS = [
'recipe.apps.RecipeConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'foodForThought'
]

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 = 'foodForThought.urls'

...

WSGI_APPLICATION = 'foodForThought.wsgi.application'

...

我目前正在使用 Django 1.11.7 并在 venv 中进行测试。是什么原因导致出现此问题?

最佳答案

这对我有用,我知道我迟到了 11 个月,但我希望它对面临这个问题的任何人都有用。根据 Whitenoise 的变更日志 here 。它说如下:

The WSGI integration option for Django (which involved editing wsgi.py) has been removed. Instead, you should add WhiteNoise to your middleware list in settings.py and remove any reference to WhiteNoise from wsgi.py. See the documentation for more details.

我按照他们说的做了,我从我的 wsgi.py 文件中删除了所有与 Whitenoise 相关的行,并在我的 设置中的 MIDDLEWARE 中更改了这两行。 py 文件:

'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',

而且,这实际上对我有用。希望它对你们有用!

关于python - Django错误: 'myproject.wsgi.application' could not be loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47624099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com