First make sure settings_production.py
is in the same directory as settings.py
.
Since you are inheriting from settings you can add at the bottom of settings.py
:
try:
from settings_production import *
except ImportError:
pass
If you want to only use settings_production.py
make sure it has all the settings for your application (database, et. al.) then:
DJANGO_SETTINGS_MODULE=settings_production python manage.py syncdb
Edit
I was going to post it as a comment, but it became too long:
I did it this way because typically in production one only changes a few values you can import in the master settings.py
; and the last value of the variable is used (so if you set production db in settings_production.py
, then that setting is used).
It is easier this way since django by default will look for settings.py
; avoids having to deal with environment variables and import paths especially if you are changing minor things.
There are a few draw backs to this approach; for example I can't imagine its very portable especially if you have multiple environments (staging/testing/production/dev), as then you have multiple from _foo_ import *
statements and it can lead to problems because the order of imports becomes significant; if you forgot and kept around a stray settings_*.py
around - for example the test environment also got the dev file because some developer forgot to remove it from the test branch.
For more complex setups its easier to keep complete copies of the master settings.py
file; and then point DJANGO_SETTINGS_MODULE
to the python path of those files. The caveat here is that you have to make sure PYTHONPATH
is adjusted to include the location of your settings.
For more ideas, see the SplitSettings wiki entry.