Search code examples
djangoamazon-web-servicesamazon-elastic-beanstalk

Deploy Django on Amazon Elastic Beanstalk. LOGGING_INFO environment variable not set


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.


Solution

  • 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?