public
Last active

Script to create django project with virtualenv

  • Download Gist
django_one_step.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
#!/bin/bash
 
#Take project name as input
if [ -z "$1" ]
then
echo "Enter project name"
read proj
else
proj="$1"
fi
 
#Create a virtualenv
virtualenv $proj
cd $proj
source bin/activate
 
 
 
#Install django within the virtualenv
echo "PIP_RESPECT_VIRTUALENV=true" >> bin/activate
touch requirements.txt
echo "django" >> requirements.txt
pip install -r requirements.txt
 
#Create project
python lib/python2.7/site-packages/django/bin/django-admin.py startproject $proj
 
#Set default environment variables
export DJANGO_SETTINGS_MODULE="$proj.settings"
export PYTHONPATH="$VIRTUAL_ENV/$proj"
 
#Write the variables into activate for future use.
echo "export DJANGO_SETTINGS_MODULE=$proj.settings" >> bin/activate
echo "export PYTHONPATH=$VIRTUAL_ENV/$proj" >> bin/activate
 
#Reset virtualenv and we are ready
deactivate
source bin/activate

Usage:
$ chmod +x django_one_step.sh
$ ./django_one_step.sh your_project

http://intendindent.blogspot.in/2012/10/script-to-create-django-project-with.html

Oops, missed out one more command
$ chmod +x django_one_step.sh
$ ./django_one_step.sh your_project
$ source bin/activate

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.