Skip to content

Instantly share code, notes, and snippets.

@JordanReiter
Created June 7, 2012 15:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JordanReiter/2889330 to your computer and use it in GitHub Desktop.
Save JordanReiter/2889330 to your computer and use it in GitHub Desktop.
Some bash functions that make working with Django && virtualenv a lot easier
#!/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 $*
}
@slacy
Copy link

slacy commented Jun 7, 2012

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.

@kennethlove
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment