3 ms·
I have a common settings.py file which starts with: ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) configs = { '/path/to/my/local/dev/folder'
by alexatkeplar 15y ago
I have a common settings.py file which starts with:
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
configs = {
'/path/to/my/local/dev/folder': 'alex',
'/var/www/www.mywebsite.com/test/private/django/mywebsite': 'test',
'/var/www/www.mywebsite.com/prod/private/django/mywebsite': 'prod'
}
config_module = __import__('config.%s' % configs[ROOT_PATH], globals(), locals(), 'mywebsite')
for setting in dir(config_module):
if setting == setting.upper():
locals()[setting] = getattr(config_module, setting)
Then I have alex.py, prod.py and test.py all in a config subfolder. All under version control, with my settings.py automatically choosing the right environment based on where it's deployed to.