[Answer]-Deploy Django on Amazon Elastic Beanstalk. LOGGING_INFO environment variable not set

0👍

So after trying what feels like everything I eventually got the sample Django project to load. I changed this line:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

to this line

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

in wsgi.py.

Why is it that it works now?

👤Gustaf

1👍

I have also added this to most files:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

That piece of code only needs to be placed in your .wsgi file . It has no use elsewhere.

Now, once you’ve done that, here’s why the setdefault method isn’t doing the same stuff like the manual assignment does:

The key problem is what the setdefault() method does when setting the
environment variable DJANGO_SETTINGS_MODULE compared to using
assignment as previously. In the case of assignment the environment
variable is always updated. For setdefault(), it is only updated if it
is not already set.

via this. Hope this makes it clear.

👤DoiDor

Leave a comment