我安装了几乎全新的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()
什么原因可能导致此问题?
最近发生在我身上,但这是因为我正在为一个更复杂的项目重新配置设置。我在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
)排除在等式之外,并可能为您提供其他线索。