Forums

Error running WSGI application: Improperly configured ...

Hi I am trying to get PA working for the first time but am having trouble with the following error. I am running Python 2.7 and Django 1.9. I have checked that these are the versions that are running in my virtual environment.

2017-05-25 05:50:15,504: Error running WSGI application
2017-05-25 05:50:15,509: ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
2017-05-25 05:50:15,509:   File "/var/www/chriswardchrisward_pythonanywhere_com_wsgi.py", line 15, in <module>
2017-05-25 05:50:15,509:     application = get_wsgi_application()
2017-05-25 05:50:15,509: 
2017-05-25 05:50:15,510:   File "/home/chriswardchrisward/.virtualenvs/SST/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
2017-05-25 05:50:15,510:     django.setup()
2017-05-25 05:50:15,510: 
2017-05-25 05:50:15,511:   File "/home/chriswardchrisward/.virtualenvs/SST/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
2017-05-25 05:50:15,511:     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2017-05-25 05:50:15,511: 
2017-05-25 05:50:15,511:   File "/home/chriswardchrisward/.virtualenvs/SST/local/lib/python2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__
2017-05-25 05:50:15,512:     self._setup(name)
2017-05-25 05:50:15,512: 
2017-05-25 05:50:15,512:   File "/home/chriswardchrisward/.virtualenvs/SST/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
2017-05-25 05:50:15,512:     % (desc, ENVIRONMENT_VARIABLE))

Any help would be greatly appreciated

in your wsgi.py file, do you have the environment variable DJANGO_SETTINGS_MODULE set? this should be set automatically if you go through the normal create webapp process- but perhaps you manually edited that file and took it out?

I have changed some things inside my wsgi.py file but I was under the impression from the Deploy an existing Django Project guide that Python anywhere system ignores that file.

That file looks as follows:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings")
from django.conf import settings

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

application = get_wsgi_application()
# application = DjangoWhiteNoise(application)

if not settings.DEBUG:
    try:
        application = get_wsgi_application()
        application = DjangoWhiteNoise(application)
    except:
        pass

while the PythonAnywhere wsgi file looks as follows

import os
import sys

# assuming your django settings file is at '/home/chriswardchrisward/mysite/mysite/settings.py'
# and your manage.py is is at '/home/chriswardchrisward/mysite/manage.py'
path = '/home/chriswardchrisward/swanson_speech_therapy2/blog/src'
if path not in sys.path:
    sys.path.append(path)

# os.environ['DJANGO_SETTINGS_MODULE'] = 'blog.settings'

# then, for django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# or, for older django <=1.4
# import django.core.handlers.wsgi
# application = django.core.handlers.wsgi.WSGIHandler()

It looks like some of wsgi.py is artifacts from attempting to deploy my site on Heroku (facepalm). But now I am unsure of what actually needs to be in that file. Everything works locally.

PythonAnywhere ignores the wsgi.py that's part of your Django project -- the only one you need to set up is the one that's linked from the "Web" tab.

Looking at the code you provided above, I think all you need to do to get this working is to uncomment the line

os.environ['DJANGO_SETTINGS_MODULE'] = 'blog.settings'

...then reload the site on the "Web" tab.

Thanks for your answer giles, your below suggestion fixed my problem as well!

PythonAnywhere ignores the wsgi.py that's part of your Django project -- the only one you need to set up is the one that's linked from the "Web" tab.