I use a settings module that is not a single file:
settings/
__init__.py
_base.py
_servers.py
development.py
production.py
testing.py
The __init__.py
file is simple:
from _servers import get_server_type
exec("from %s import *" % get_server_type())
The _base.py
file contains all of the common settings across all server types.
The _servers.py
file contains a function get_server_type()
that uses socket.gethostname()
to determine what type of server the current machine is: it returns development
, production
or testing
.
Then the other files look a bit like (production.py
):
DEBUG=False
TEMPLATE_DEBUG=False
from _base import *
In each of these files, I put in the settings that only apply to this server type.