Django ImproperlyConfigured: WSGI application '

2019-03-28 06:32发布

问题:

I have an almost fresh install of django and when I try to python manage.py runserver.It is is giving me this error:

ImproperlyConfigured: WSGI application 'myproject.wsgi.application' could not be loaded; Error importing module.

settings.py

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()

回答1:

Comment out the

#'django.contrib.auth.middleware.SessionAuthenticationMiddleware',

in your settings.py file in Middleware



回答2:

I encountered the same problem because I added the debug_toolbar Middleware to my settings.py

'debug_toolbar.middleware.DebugToolbarMiddleware',

I solved the problem by removing the debug_toolbar Middleware. I also had to remove debug_toolbar from my INSTALLED APPS.



回答3:

From my experience this happens when I try to execute runserver but the I haven't installed all custom MIDDLEWARE in setting.py. After identifying and installing the middlewares the error is resolved.



回答4:

Check for the stack trace - you might find answer few lines above the line "The above exception was the direct cause of the following exception:"

It may caused for example by using of middleware from some uninstalled third party app etc.



回答5:

Check the settings.py,

MIDDLEWARE=[
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

remove 'whitenoise.middleware.WhiteNoiseMiddleware', or install Whitenoise (pip install whitenoise)