Setting DJANGO_SETTINGS_MODULE
By Chris Gemignani
April 30, 2008
Find more about:
django
python
bash
tools
Here's a bash function I use for Django development to quickly set DJANGO_SETTINGS_MODULE.
function setdsm() {
# add the current directory and the parent directory to PYTHONPATH
# sets DJANGO_SETTINGS_MODULE
export PYTHONPATH=$PYTHONPATH:$PWD/..
export PYTHONPATH=$PYTHONPATH:$PWD
if [ -z "$1" ]; then
x=${PWD/\/[^\/]*\/}
export DJANGO_SETTINGS_MODULE=$x.settings
else
export DJANGO_SETTINGS_MODULE=$1
fi
echo "DJANGO_SETTINGS_MODULE set to $DJANGO_SETTINGS_MODULE"
}
I put this in my .bash_profile, then a quick setdsm sets the DJANGO_SETTINGS_MODULE to the settings.py in the current directory and add the current directory and it's parent to PYTHONPATH.
This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. All source code is released under a BSD License unless otherwise specified.





8 comments | Show all comments only the last 5 are shown
Ro said:
Hi Chris,
1. i put the script into .bash_profile, which i had to create first
2. then i opened the konsole, entered into my projects dir which is on a windows drive (sth like /media/sda2/Document .../..),
3. called `django-admin.py runserver`
but i got the error "Settings cannot be imported because environment variable DJANGO_SETTINGS_MODULE is undefined"
any suggestion what might be the problem?
Boffo Bob said:
"windows drive" is the problem.
wtflol
Not Boffo Bob said:
Works - excellent.
Sampath Girish.M said:
Hi Chris Gemignani,
I am getting an error while running the following command 'python manage.py shell'
as:
function setdsm() error at '()'
I copied the function you placed here and got that error. Is there any rectification for the above problem, u can help me out and I will be very much thankful to u......
If possible post a reply to my email id please..... Its girishmsampath@gmail.com
so that i can solve my problem faster.
Thanks,
Sampath Girish.M
carter said:
Dude, you rock!
Been trying to get Django going and setdsm did it!
PhilGo20 said:
Thanks ! Exactly what I needed when I needed !
Richard Careaga said:
You are a benefactor to mankind. A braincramp was causing me to omit the parent directory.
tomtaylorr said:
I have Ankylosing Spondylitis, Ti's a bugger an nae mistake but you learn to live with it.You cannae catch it and I dinnae need help (Except wi liftin). Stop hiding away, Step up tae the mike an gie it laldy :0)
<a href="http://www.windows7tests.com">windows 7 certification</a>
said:
Add a comment