django.core.exceptions.ImproperlyConfigured:WSGI应用程序'myproject.wsgi.application'无法加载;导入模块时出错

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

我安装了几乎全新的django,并且当我尝试使用python manage.py runserver时。它给了我这个错误:

 File "C:\Users\..\lib\site-packages\django\core\servers\basehttp.py", line 50, in ge
t_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'myproject.wsgi.application' could not be loaded; Error importing module.

settings.py

INSTALLED_APPS = [
    'cognitive.apps.CognitiveConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'jchart',
]

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

WSGI_APPLICATION = 'myproject.wsgi.application'

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')

application = get_wsgi_application()

什么原因可能导致此问题?

python django pycharm
1个回答
0
投票

最近发生在我身上,但这是因为我正在为一个更复杂的项目重新配置设置。我在WSGI_APPLICATION中查找了Django docs,似乎默认设置为None。因此,我在设置文件中注释了该行,然后本地开发服务器再次与./manage.py runserver一起使用。

然后,我更加清楚地阅读了文档,并指出,这是Django内置服务器(例如runserver)将使用的WSGI应用程序对象的完整Python路径。”当此设置为None时,Django将调用django.core.wsgi.get_wsgi_application作为后备。也许您应该尝试上面的方法以查看会发生什么。可能会为您的问题提供线索。

另一种尝试是使用django-admin runserver。这将manage.py(设置为DJANGO_SETTINGS_MODULE)排除在等式之外,并可能为您提供其他线索。

© www.soinside.com 2019 - 2024. All rights reserved.