Changes between Version 24 and Version 25 of SplitSettings


Ignore:
Timestamp:
Feb 6, 2012, 4:51:35 AM (12 years ago)
Author:
Antti Kaihola
Comment:

formatting

Legend:

Unmodified
Added
Removed
Modified
  • SplitSettings

    v24 v25  
    66passwords and such out of the main settings.py file.
    77
    8 As discussions on the django-developers mailing list have shown everybody has different
     8As discussions on the [http://groups.google.com/group/django-developers django-developers mailing list] have shown everybody has different
    99requirements and ideas how to do this. This page is meant to collect some of these ideas for future reference.
    1010
    11 One thing to keep in mind is that django's config files are pure python.
     11One thing to keep in mind is that Django's config files are pure Python.
    1212This gives you the ultimate flexibility to handle configurations the way you think is best.
    1313Or to quote Adrian Holovaty:
    14 {{{
    15 We don't need a default solution for this. It's not within the scope
    16 of this project to tell people how they should organize their settings
    17 files. Take that opportunity to showcase your individualism.
    18 }}}
     14
     15  We don't need a default solution for this. It's not within the scope
     16  of this project to tell people how they should organize their settings
     17  files. Take that opportunity to showcase your individualism.
    1918
    2019
     
    2928
    3029SECRET_KEY = open(os.path.expanduser('~/.gallery-secret')).read().strip()
    31 
    3230}}}
    3331
     
    3533== ini-style file for deployment ==
    3634This is a solution that Michael Radziej posted to django-developers. His motivation was to be able to store the settings
    37 for an app he published under /etc with all the other system config files.
    38 
    39 For a similar but more transparent solution see [[SplitSettings#foxsmethod | fox's method]]
    40 
    41 /etc/whatever/settings.ini
     35for an app he published under `/etc` with all the other system config files.
     36
     37For a similar but more transparent solution see [[SplitSettings#foxsmethod|fox's method]]
     38
     39`/etc/whatever/settings.ini`
    4240{{{
    4341[database]
     
    8078[404 mail]
    8179John Wayne: john@localhost
    82 
    83 }}}
    84 
    85 
    86 /path/to/whatever/settings.py
     80}}}
     81
     82
     83`/path/to/whatever/settings.py`
    8784{{{
    8885#!python
     
    118115ADMINS = tuple(config.items('error mail'))
    119116MANAGERS = tuple(config.items('404 mail'))
    120 
    121117}}}
    122118
     
    125121This is my (Steven Armstrong) preferred solution.
    126122
    127 Keep application wide, unsensitive settings and sane defaults in your normal settings.py file.
     123Keep application wide, unsensitive settings and sane defaults in your normal `settings.py` file.
    128124
    129125/path/to/whatever/settings.py
     
    165161}}}
    166162
    167 At the end of your normal settings.py include * from an other, machine specific config file
     163At the end of your normal `settings.py` include * from an other, machine specific config file
    168164which could look something like this.
    169165
    170 /path/to/whatever/settings_local.py
     166`/path/to/whatever/settings_local.py`
    171167{{{
    172168#!python
     
    191187}}}
    192188
    193 {{{
    194 # urls.py
     189`urls.py`
     190{{{
    195191import settings
    196192     (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.BASE_DIR+'/core/static/', 'show_indexes': True}),                     
    197193}}}
    198194
    199 settings.py goes into CVS, SVN, (put your favorite RCS here)[[BR]]
    200 settings_local.py does _not_ go under RCS
    201 
    202 If wanted a settings_local.template file can be put under version control with
     195`settings.py` goes into CVS, SVN, (put your favorite RCS here)[[BR]]
     196`settings_local.py` does _not_ go under RCS
     197
     198If wanted a `settings_local.template` file can be put under version control with
    203199instructions to copy it over to settings_local.py, change it to suite the environment,
    204200and to never ever commit it to the RCS system.
     
    207203I personally use this solution.
    208204
    209 /path/to/project/settings.py
     205`/path/to/project/settings.py`
    210206{{{
    211207#!python
     
    231227}}}
    232228
    233 This settings loader will import the appropriate settings module. I store my settings files in a '''config''' directory in the root of the project.
    234 
    235 /path/to/project/config/prod.py
     229This settings loader will import the appropriate settings module. I store my settings files in a `config` directory in the root of the project.
     230
     231`/path/to/project/config/prod.py`
    236232{{{
    237233#!python
     
    256252}}}
    257253
    258 /path/to/project/config/user1.py
     254`/path/to/project/config/user1.py`
    259255{{{
    260256#!python
     
    464460}}}
    465461
    466 Then, move {{{settings.py}}} to {{{settings/common.py}}}.
     462Then, move `settings.py` to `settings/common.py`.
    467463
    468464
    469465The 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..
    470466
    471 {{{settings/dev.py}}}
     467`settings/dev.py`
    472468{{{
    473469#!python
     
    491487}}}
    492488
    493 {{{settings/$USER.py}}}
     489`settings/$USER.py`
    494490{{{
    495491#!python
     
    513509}}}
    514510
    515 Of course, you may find that you actually want some of the above settings in {{{common.py}}}. Configure however you need for your situation.
     511Of course, you may find that you actually want some of the above settings in `common.py`. Configure however you need for your situation.
    516512
    517513=== Simple Package Organization for Environments ===
     
    610606== fox's method ==
    611607First write a config file with passwords ad secret keys. Save it somewhere.
    612 This is the external_config.py
     608This is the `external_config.py`
    613609{{{
    614610#!python
     
    672668}}}
    673669
    674 This is production_settings.py
     670This is `production_settings.py`
    675671{{{
    676672#!python
     
    692688}}}
    693689
    694 Now importig * from production_settings.py will import data from the config file
     690Now importing * from {{{production_settings.py}}} will import data from the config file
Back to Top