Reputation: 838
I'm trying to setup a Django site on Heroku. I get this error message:
2017-10-07T21:03:33.416585+00:00 app[web.1]:
django.core.exceptions.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.
But if I run Heroku config, the var is set. Why is it not recognized?
=== dagenssalg Config Vars
DISABLE_COLLECTSTATIC: 0
LOGGING_CONFIG: off
Many answers in here mention the wsgi.py file, but I can't see anything wrong with that:
import os
from django.core.wsgi import get_wsgi_application
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
os.environ.setdefault("DJANGO_SETTINGS_MODULE","dagenssalg.settings")
application = get_wsgi_application()
Any help is most appreciated. Best regards Kresten
Upvotes: 0
Views: 1345
Reputation: 599630
Your wsgi file is a mess. You import get_wsgi_application
twice, then call it before setting the environment variable; you then correctly wrap the application instance with WhiteNoise, but then throw away this instance by calling get_wsgi_application
again.
Replace the whole thing with this:
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE","dagenssalg.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
Upvotes: 1