Juggling Django settings modules

Tuesday, November 6, 2007

If you find yourself juggling multiple Django projects and constantly changing the DJANGO_SETTINGS_MODULE variable, try this simple shortcut.

Upon diving into a particular project I define an alias in my .bash_profile that gets me to the project directory in as few keystrokes as possible. For example, to get to my playgroundblues directory I simply type ‘pb’ and I’m in the root of playgroundblues.com. Here is the line of code in my .bash_profile:

alias pb="cd /Working/www/playgroundblues.com/"

Pretty straight forward, however, since I’m going to that project I might as well set the DJANGO_SETTINGS_MODULE at the same time so I’ve altered the line above to:

alias pb="cd /Working/www/playgroundblues.com/; export DJANGO_SETTINGS_MODULE=playgroundblues.settings"

Now I’m in the proper directory with the proper settings file is in focus. Bliss.