Changes between Version 17 and Version 18 of SplitSettings
- Timestamp:
- Sep 16, 2011, 12:58:10 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SplitSettings
v17 v18 407 407 === Setting Inheritance with Hierarchy === 408 408 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: 409 I ([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 411 This script merges {{{settings/common.py}}}, {{{settings/$APP_ENV.py}}} and {{{settings/<developer overrides>.py}}}, in that order. 410 412 411 413 {{{settings/__init__.py}}} … … 428 430 to_dict[key] = value 429 431 430 # this should be one of prod, qa, staging, dev. default to dev for safety432 # this should be one of prod, qa, staging, dev. Default to dev for safety. 431 433 env = os.environ.get('APP_ENV', 'dev') 432 434 … … 452 454 for setting in dir(module): 453 455 # all django settings are uppercase, so this ensures we 454 # are only processing setting from the dir() call456 # are only processing settings from the dir() call 455 457 if setting == setting.upper(): 456 458 module_settings[setting] = getattr(module, setting) … … 463 465 464 466 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}}}467 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 developer specific overrides. Example files (excepting {{{settings/common.py}}}) below.. 468 469 {{{settings/dev.py}}} 468 470 {{{ 469 471 #!python … … 482 484 # Don't forget to use absolute paths, not relative paths. 483 485 484 # project templates directory486 # automatically inject project templates directory into the dev env 485 487 '%s/templates' % ( project_path ) 486 488 ) 487 489 }}} 488 490 489 {{{ $USER.py}}}491 {{{settings/$USER.py}}} 490 492 {{{ 491 493 #!python … … 508 510 } 509 511 }}} 512 513 Of course, you may find that you actually want some of the above settings in {{{common.py}}}. Configure however you need for your situtation.