Skip to content

Instantly share code, notes, and snippets.

@pixyj
Created October 27, 2012 10:11
Show Gist options
  • Save pixyj/3963953 to your computer and use it in GitHub Desktop.
Save pixyj/3963953 to your computer and use it in GitHub Desktop.
Script to create django project with virtualenv
#!/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
@pixyj
Copy link
Author

pixyj commented Oct 27, 2012

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

@pixyj
Copy link
Author

pixyj commented Oct 27, 2012

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

@pixyj
Copy link
Author

pixyj commented Oct 27, 2012

OK, hopefully final change to usage. Now it's truly one-step.

$ source django_one_step.sh

http://stackoverflow.com/questions/13098457/installing-django-with-pip-django-admin-not-found/13099492#13099492

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