How to fix Django, Apache VirtualHost, mod_wsgi and DJANGO_SETTINGS_MODULE
2014-06-13 11:31:56 +0000I’ve spent countless hours trying to fix Django installations running on legacy Apache servers, these usually recurring every few months, a time span long enough to forget how the last fix was done. And for some reason, the docs are not mentioning this crucial features AT ALL! In the official Django + mod_wsgi documentation page, they don’t mention something so irrelevant such as THE MAIN DJANGO SETTINGS FILE?
For future memory, here's a solution that makes me happy, and hopefully next time will only be a few minutes headache (although I already know it won't be the case...)
- copy the default wsgi.py to a new file called apache_wsgi.py
- modify the new apache_wsgi.py so that it reads:
- now open your virtualhost configuration file and check it contains the following
- almost there! create a /settings folder sibling of settings.py, put an empty __init__.py in it, then move settings.py inside that folder, rename it to common.py and create a new pick_settings_file_name.py with a single liner in it
VOILAAAAAAAAAAAAAAA!!!!
just restart your apache and everything will work. in your pick_settings_file_name.py you will have configurations specific for your environment (i.e. multiple copies of the file for dev, staging: project_dev.py, project_staging.py)