django.core.exceptions.ImproperlyConfigured: WSGI

2020-07-07 05:37发布

问题:

The scenario is,

I cloned the Django code for OpenShift-V3 from here . When I run the code using python manage.py runserver getting an error as,

django.core.exceptions.ImproperlyConfigured: WSGI application 'application' could not be loaded; Error importing module: 'application doesn't look like a module path

I didn't add anything to the code and the required packages are already satisfied.

回答1:

Go to django-ex/project/settings.py

Change the line in settings.py as below

WSGI_APPLICATION = 'application' to WSGI_APPLICATION = 'wsgi.application'

That's it :(



回答2:

I used a middleware CorsMiddleware but forget to install it so after install, it works perfectly.

pip install django-cors-headers.

So check something like it you may miss something like it.



回答3:

If you run django project locally for development, just remove WSGI_APPLICATION variable from settings.py module. It needs in prod/stage settings, for example settings_prod.py



回答4:

in settings.py file change as follows:

WSGI_APPLICATION = 'your_project_name.wsgi.application'



回答5:

Do you have Django Debug Toolbar

Remove it and check if the problem goes away. Possible occurences:

pip uninstall django-debug-toolbar

INSTALLED_APPS = [
    ...
    'debug_toolbar',
    ...
]

MIDDLEWARE = [
    ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    ...
]



回答6:

note that any error in importing modules anywhere prior to starting the wsgi application will also prompt this message, so first look at the trace and start from the top in fixing issues.

I ported a Django app from python 2.7 to python3 and add all sorts of module import issues, not connected to this issue directly.



回答7:

I was using django-cors-headers, then I thought I haven't implemented cors in my project, so went ahead to install django-cors-middleware, then it's started giving the wsgi exception, so i checked the stack trace and I found out that it's django-cors-headers and django-cors-middleware conflicting each other. I had to uninstall django-cors-middleware but it's still gives the same exception, so uninstall django-cors-headers too then reinstall and everything works fine....



回答8:

Read carefully, it might say "The above exception was the direct cause of the following exception: ...". And the "above exception" being you forgot to install whitehoise. Run pip install whitenoise, it worked for me.



回答9:

Make sure you are in desired python Environment

Get the requirements.txt file or the python modules list, which are needed to execute django.

Install all the Modules and you shall be good to go.