Changes between Version 24 and Version 25 of SplitSettings
- Timestamp:
- Feb 6, 2012, 4:51:35 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SplitSettings
v24 v25 6 6 passwords and such out of the main settings.py file. 7 7 8 As discussions on the django-developers mailing listhave shown everybody has different8 As discussions on the [http://groups.google.com/group/django-developers django-developers mailing list] have shown everybody has different 9 9 requirements and ideas how to do this. This page is meant to collect some of these ideas for future reference. 10 10 11 One thing to keep in mind is that django's config files are pure python.11 One thing to keep in mind is that Django's config files are pure Python. 12 12 This gives you the ultimate flexibility to handle configurations the way you think is best. 13 13 Or 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. 19 18 20 19 … … 29 28 30 29 SECRET_KEY = open(os.path.expanduser('~/.gallery-secret')).read().strip() 31 32 30 }}} 33 31 … … 35 33 == ini-style file for deployment == 36 34 This 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 /etcwith 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 35 for an app he published under `/etc` with all the other system config files. 36 37 For a similar but more transparent solution see [[SplitSettings#foxsmethod|fox's method]] 38 39 `/etc/whatever/settings.ini` 42 40 {{{ 43 41 [database] … … 80 78 [404 mail] 81 79 John Wayne: john@localhost 82 83 }}} 84 85 86 /path/to/whatever/settings.py 80 }}} 81 82 83 `/path/to/whatever/settings.py` 87 84 {{{ 88 85 #!python … … 118 115 ADMINS = tuple(config.items('error mail')) 119 116 MANAGERS = tuple(config.items('404 mail')) 120 121 117 }}} 122 118 … … 125 121 This is my (Steven Armstrong) preferred solution. 126 122 127 Keep application wide, unsensitive settings and sane defaults in your normal settings.pyfile.123 Keep application wide, unsensitive settings and sane defaults in your normal `settings.py` file. 128 124 129 125 /path/to/whatever/settings.py … … 165 161 }}} 166 162 167 At the end of your normal settings.pyinclude * from an other, machine specific config file163 At the end of your normal `settings.py` include * from an other, machine specific config file 168 164 which could look something like this. 169 165 170 /path/to/whatever/settings_local.py 166 `/path/to/whatever/settings_local.py` 171 167 {{{ 172 168 #!python … … 191 187 }}} 192 188 193 {{{ 194 # urls.py 189 `urls.py` 190 {{{ 195 191 import settings 196 192 (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.BASE_DIR+'/core/static/', 'show_indexes': True}), 197 193 }}} 198 194 199 settings.pygoes into CVS, SVN, (put your favorite RCS here)[[BR]]200 settings_local.pydoes _not_ go under RCS201 202 If wanted a settings_local.templatefile can be put under version control with195 `settings.py` goes into CVS, SVN, (put your favorite RCS here)[[BR]] 196 `settings_local.py` does _not_ go under RCS 197 198 If wanted a `settings_local.template` file can be put under version control with 203 199 instructions to copy it over to settings_local.py, change it to suite the environment, 204 200 and to never ever commit it to the RCS system. … … 207 203 I personally use this solution. 208 204 209 /path/to/project/settings.py 205 `/path/to/project/settings.py` 210 206 {{{ 211 207 #!python … … 231 227 }}} 232 228 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 229 This 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` 236 232 {{{ 237 233 #!python … … 256 252 }}} 257 253 258 /path/to/project/config/user1.py 254 `/path/to/project/config/user1.py` 259 255 {{{ 260 256 #!python … … 464 460 }}} 465 461 466 Then, move {{{settings.py}}} to {{{settings/common.py}}}.462 Then, move `settings.py` to `settings/common.py`. 467 463 468 464 469 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 developer specific overrides. Example files (excepting {{{settings/common.py}}}) below.. 470 466 471 {{{settings/dev.py}}} 467 `settings/dev.py` 472 468 {{{ 473 469 #!python … … 491 487 }}} 492 488 493 {{{settings/$USER.py}}} 489 `settings/$USER.py` 494 490 {{{ 495 491 #!python … … 513 509 }}} 514 510 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.511 Of course, you may find that you actually want some of the above settings in `common.py`. Configure however you need for your situation. 516 512 517 513 === Simple Package Organization for Environments === … … 610 606 == fox's method == 611 607 First write a config file with passwords ad secret keys. Save it somewhere. 612 This is the external_config.py608 This is the `external_config.py` 613 609 {{{ 614 610 #!python … … 672 668 }}} 673 669 674 This is production_settings.py670 This is `production_settings.py` 675 671 {{{ 676 672 #!python … … 692 688 }}} 693 689 694 Now importi g * from production_settings.pywill import data from the config file690 Now importing * from {{{production_settings.py}}} will import data from the config file