Inspired during DjangoCon 2011. After creating six projects to test during the talks, I realized that setting up the
settings.py file to be more modular was a real pain. I wrote this little script to automate the process.
Django's default way of doing settings kind of sucks. Adding:
try: from local_settings import * except ImportError: pass
to the bottom of the
settings.py works, but it doesn't allow you to extend settings. So, for example, you can't add
django-debug-toolbar to just your local development without overriding the entire
What this script does:
- Read in your current settings.
- Creates a new folder named
settingswithin the project directory.
- Writes your current settings to
base.pywithin the new settings package.
- Creates a basic
__init__.pyfile which imports
base.pyand looks for
- Creates an empty
local.pyfor your dev environment.
- Deletes the default
settings.pyc, should it exist).
What You Get
Now you can edit
local.py for your dev environment and extend things like
INSTALLED_APPS but just for you.
INSTALLED_APPS += ( 'debug_toolbar', ) MIDDLEWARE_CLASSES += ( 'debug_toolbar.middleware.DebugToolbarMiddleware', ) INTERNAL_IPS = ('127.0.0.1',)
This is a simple script that does not need to be installed or compiled. It's a run-once-and-discard project. You will want to
modular_settings.py file to your project directory. Specifically to the directory where the default Django
settings.py file resides.
curl -O https://raw.github.com/chrisjones-brack3t/django-modular-settings/master/modular_settings.py
Or, if you prefer wget:
After downloading the file, run the script from your project directory.
Assuming everything goes as planned, you should see a message saying your settings are now a little more awesome.