public
Created

Some bash functions that make working with Django && virtualenv a lot easier

  • Download Gist
django_env_functions.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/bin/bash
#
# Helper functions for Django projects in virtual env
#
# include in your .bashrc file:
#
# . ~/django_env_functions.sh
#
 
$MANAGE_PATH = "project/code"
 
function myenv() {
deactivate
cd /path/to/myenv/
source bin/activate
export DJANGO_SETTINGS_MODULE="settings"
}
 
function testenv() {
deactivate
cd /path/to/myenv/
source bin/activate
export DJANGO_SETTINGS_MODULE="test_settings"
}
 
function collectstatic() {
# run collect static for environment & automatically say yes
django-admin.py collectstatic --noinput --settings $DJANGO_SETTINGS_MODULE
}
 
function dshell() {
# run shell for active environment
django-admin.py shell --settings $DJANGO_SETTINGS_MODULE
}
 
function dj() {
# run arbitrary django commands
django-admin.py $*
}

If you're using Django inside virtualenv, then all your $VIRTUAL_ENV/$MANAGE_PATH/manage.py should really just be $VIRTUAL_ENV/bin/django-admin.py or better yet just django-admin.py since when you're activated, it will already be on your path.

you can run collectstatic --noinput --settings [...] to not have to use yes.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.