Deploy Django on Amazon Elastic Beanstalk. LOGGING_INFO environment variable not set
Question: I am successfully deploying my Django (1.7) on Elastic Beanstalk, but I get
500 when I load it in the browser. In the logs I find this:

    
    
    [Wed Sep 24 12:56:11.434509 2014] [:error] [pid 27030] [remote 172.31.6.176:0] mod_wsgi (pid=27030): Target WSGI script '/opt/python/current/app/mysite/wsgi.py' cannot be loaded as Python module.
    [Wed Sep 24 12:56:11.434557 2014] [:error] [pid 27030] [remote 172.31.6.176:0] mod_wsgi (pid=27030): Exception occurred processing WSGI script '/opt/python/current/app/mysite/wsgi.py'.
    [Wed Sep 24 12:56:11.434596 2014] [:error] [pid 27030] [remote 172.31.6.176:0] Traceback (most recent call last):
    [Wed Sep 24 12:56:11.434636 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/current/app/mysite/wsgi.py", line 14, in <module>
    [Wed Sep 24 12:56:11.434698 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     application = get_wsgi_application()
    [Wed Sep 24 12:56:11.434721 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    [Wed Sep 24 12:56:11.434759 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     django.setup()
    [Wed Sep 24 12:56:11.434781 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
    [Wed Sep 24 12:56:11.434813 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
    [Wed Sep 24 12:56:11.434835 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
    [Wed Sep 24 12:56:11.434867 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     self._setup(name)
    [Wed Sep 24 12:56:11.434886 2014] [:error] [pid 27030] [remote 172.31.6.176:0]   File "/opt/python/run/venv/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    [Wed Sep 24 12:56:11.434916 2014] [:error] [pid 27030] [remote 172.31.6.176:0]     % (desc, ENVIRONMENT_VARIABLE))
    [Wed Sep 24 12:56:11.435013 2014] [:error] [pid 27030] [remote 172.31.6.176:0] 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.
    

I am setting the settings file in my .ebextension mysite.config file like
this.

    
    
      - option_name: DJANGO_SETTINGS_MODULE
        value: "mysite.settings"
    

I have also added this to most files:

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

Where the problem is how my settings file should look like. I have googled
this for a good few hours now, but I can't get it to work... I am not even
sure how my settings file should look like. Now it just looks like this:

    
    
    LOGGING_CONFIG = 'django.utils.log.dictConfig'
    

I am pretty sure it is the settings file that is the problem. If anyone could
point me in the right direction I would be so grateful.


Answer: > 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](http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-
django.html). Hope this makes it clear.

