Changes between Version 21 and Version 22 of SplitSettings


Ignore:
Timestamp:
Dec 24, 2011, 4:55:16 PM (13 years ago)
Author:
daenney
Comment:

add another method to work with local settings

Legend:

Unmodified
Added
Removed
Modified
  • SplitSettings

    v21 v22  
    571571
    572572[http://tech.yipit.com/author/adam-nelson/ Adam Nelson] from [http://yipit.com/ Yipit] blogged about their method of managing Django settings. See [http://tech.yipit.com/2011/11/02/django-settings-what-to-do-about-settings-py/ Extending Django Settings for the Real World]. TODO: summarize the blog post here.
     573
     574== Rob Golding's method ==
     575Rob Golding posted on his blog how he solved this issue. It's a bit of a hack really but it works nicely and allows you to override or extend anything in {{{settings.py}}}.
     576
     577Add this to the bottom of {{{settings.py}}}:
     578{{{
     579#!python
     580try:
     581    LOCAL_SETTINGS
     582except NameError:
     583    try:
     584        from local_settings import *
     585    except ImportError:
     586        pass
     587}}}
     588
     589Now create a {{{local_settings.py}}} with the following:
     590{{{
     591#!python
     592LOCAL_SETTINGS = True
     593from settings import *
     594}}}
     595
     596You can now add things to {{{local_settings.py}}} like this:
     597{{{
     598#!python
     599MIDDLEWARE_CLASSES +=
     600('debug_toolbar.middleware.DebugToolbarMiddleware',)
     601INTERNAL_IPS = ('127.0.0.1',)
     602INSTALLED_APPS += ('debug_toolbar',)
     603}}}
     604
     605This does however have the drawback of {{{settings.py}}} being parsed twice but that shouldn't cause any sort of mention worthy performance loss.
Back to Top