Juggling Django settings modules
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.
Remarks
Wilson Miner http://www.wilsonminer.com/
Awesome. I had a similar set of aliases set up for the runserver commands for all my different projects with the settings flag prefilled, but this is a nice general shortcut.
Jeff Croft http://jeffcroft.com/
I do this exact same thing. Works beautifully. Good tip!
sandro http://turriate.com
huh, I never knew aliases were so prevalent in the django crowd, I’ve used symbolic links in the past for current projects but I’ll have to rethink that in the future
Nathan Borror http://www.playgroundblues.com
@sandro - Not alias in the Mac OS sense. An alias in bash scripting is merely a shortcut for repetitive command line statements. They reside in your .bash_profile which should exist in your home directory. Sometimes you have to create it.
sandro
@Nathan - Thanks for the clarification but fortunately, I use linux full time so I’m well aware of aliases =). It just seems easier for me to create symbolic links for current projects rather than aliases. I try not to hack on my .profile unnecessarily, and for some reason, I don’t often need to export DJANGO_SETTINGS_MODULE.
kevin http://www.scribesonic.com
been doing something similar as well. I use the alias, but I always have a [project].sh bash script I execute where i set various vars like PYTHONPATH, DJANGO_SETTINGS_MODULE and then it executes django-admin.py accepting args…so it’s like my own little custom manage.py per project.