Changes between Version 1 and Version 2 of SplitSettings


Ignore:
Timestamp:
09/19/06 23:29:02 (8 years ago)
Author:
nbstrite
Comment:

Added a settings.py example that allows for configuring environment/machine specific configuration loading.

Legend:

Unmodified
Added
Removed
Modified
  • SplitSettings

    v1 v2  
    187187instructions to copy it over to settings_local.py, change it to suite the environment,
    188188and to never ever commit it to the RCS system.
     189
     190== Development/Machine Dependant Settings Configuration ==
     191I personally use this solution.
     192
     193/path/to/project/settings.py
     194{{{
     195#!python
     196# Django project settings loader
     197import os
     198ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
     199
     200# You can key the configurations off of anything - I use project path.
     201configs = {
     202    '/path/to/user1/dev/project': 'user1',
     203    '/path/to/user2/dev/project': 'user2',
     204    '/path/to/qa/project': 'qa',
     205    '/path/to/prod/project': 'prod',
     206}
     207
     208# Import the configuration settings file - REPLACE projectname with your project
     209config_module = __import__('config.%s' % configs[ROOT_PATH], globals(), locals(), 'projectname')
     210
     211# Load the config settings properties into the local scope.
     212for setting in dir(config_module):
     213    if setting == setting.upper():
     214        locals()[setting] = getattr(config_module, setting)
     215}}}
     216
     217This settings loader will import the appropriate settings module. I store my settings files in a '''config''' directory in the root of the project.
     218
     219/path/to/project/config/prod.py
     220{{{
     221#!python
     222
     223DEBUG = False
     224TEMPLATE_DEBUG = DEBUG
     225
     226# don't want emails while developing
     227ADMINS = ()
     228MANAGERS = ADMINS
     229
     230DATABASE_ENGINE = 'mysql'
     231DATABASE_NAME = 'mydbname'
     232DATABASE_USER = 'mydbuser'
     233DATABASE_PASSWORD = 'mydbpassword'
     234DATABASE_HOST = 'localhost'
     235DATABASE_PORT = ''
     236
     237SECRET_KEY = 'random-string-of-ascii'
     238
     239# More production settings
     240}}}
     241
     242/path/to/project/config/user1.py
     243{{{
     244#!python
     245# Load the production settings that we will overwrite as needed in our user1 settings file.
     246from projectname.config.prod import *
     247
     248DEBUG = True
     249
     250DATABASE_NAME = 'devdbname'
     251
     252# More development/maching specific settings
     253}}}
Back to Top