Changes between Version 17 and Version 18 of SplitSettings


Ignore:
Timestamp:
09/16/2011 12:58:10 AM (4 years ago)
Author:
karim.nassar@…
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SplitSettings

    v17 v18  
    407407=== Setting Inheritance with Hierarchy ===
    408408
    409 I need to be able to inherit from a base settings file, then for each environment provide overrides. In dev env, we need developer specific settings. The following extends [http://djangopeople.net/cordis  Sergey Yushckeyev's] solution above:
     409I ([http://twitter.com/#!/karim_a_nassar Karim A. Nassar]) need to be able to inherit from a base settings file, then for each environment provide overrides. In dev env, we need developer specific settings. The following extends [http://djangopeople.net/cordis  Sergey Yushckeyev's] solution above.
     410
     411This script merges {{{settings/common.py}}}, {{{settings/$APP_ENV.py}}} and {{{settings/<developer overrides>.py}}}, in that order.
    410412
    411413{{{settings/__init__.py}}}
     
    428430            to_dict[key] = value
    429431
    430 # this should be one of prod, qa, staging, dev. default to dev for safety
     432# this should be one of prod, qa, staging, dev. Default to dev for safety.
    431433env = os.environ.get('APP_ENV', 'dev')
    432434
     
    452454    for setting in dir(module):
    453455        # all django settings are uppercase, so this ensures we
    454         # are only processing setting from the dir() call
     456        # are only processing settings from the dir() call
    455457        if setting == setting.upper():
    456458            module_settings[setting] = getattr(module, setting)
     
    463465
    464466
    465 The above defaults to {{{dev}}} env. You could pass in anything to {{{manage.py}}} via the {{{APP_ENV}}} environment variable. Common ones would be {{{prod}}}, {{{staging}}}, {{{qa}}}, etc. For each {{{APP_ENV}}}, you create a file {{{$APP_ENV.py}}}. Finally, create {{{$USER.py}}} file with overrides. Example files (excepting settings.py) below..
    466 
    467 {{{dev.py}}}
     467The above defaults to {{{dev}}} env. You could pass in anything to {{{manage.py}}} via the {{{APP_ENV}}} environment variable. Common ones would be {{{prod}}}, {{{staging}}}, {{{qa}}}, etc. For each {{{APP_ENV}}}, you create a file {{{$APP_ENV.py}}}. Finally, create {{{$USER.py}}} file with developer specific overrides. Example files (excepting {{{settings/common.py}}}) below..
     468
     469{{{settings/dev.py}}}
    468470{{{
    469471#!python
     
    482484    # Don't forget to use absolute paths, not relative paths.
    483485
    484     # project templates directory
     486    # automatically inject project templates directory into the dev env
    485487    '%s/templates' % ( project_path )
    486488)
    487489}}}
    488490
    489 {{{$USER.py}}}
     491{{{settings/$USER.py}}}
    490492{{{
    491493#!python
     
    508510}
    509511}}}
     512
     513Of course, you may find that you actually want some of the above settings in {{{common.py}}}. Configure however you need for your situtation.
Back to Top