In some of my Django apps I'm using a settings_local.py
file to override settings that are different on various environments (e.g. development, test and production). I have originally used the following code to include its contents in the settings.py
:
try:
from settings_local import *
except ImportError:
sys.stderr.write("The settings_local.py file is missing.\n")
DEBUG=False
I have recently found the execfile
function and switched to something like:
try:
execfile(path.join(PROJECT_ROOT, "settings_local.py"))
except IOError:
sys.stderr.write("The settings_local.py file is missing.\n"
DEBUG=False
Both work as intended, but I'm curious whether I'm missing any gotchas, and in general which approach is more recommended and why.