Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to initialize new django project
#!/bin/bash
#
# Author: Abdallah Deeb <abdallah@deeb.me>
# Requirements: python, pip, virtualenv, virutalenvwrapper, git
#
# Edit the following 2 lines
PROJECTNAME=proj
APPNAME=myapp
if [ -n "$2" ]
then
APPNAME="$2"
fi
if [ -n "$1" ]
then
PROJECTNAME=$1
fi
source `which virtualenvwrapper.sh`
echo "Starting a new Django project: $PROJECTNAME"
# Make a virtualenv
mkvirtualenv $PROJECTNAME
# Install latest django and start the project/app
pip install django
django-admin.py startproject $PROJECTNAME
cd $PROJECTNAME
django-admin.py startapp $APPNAME
mv $PROJECTNAME conf
# conf is much nicer than projname
replace $PROJECTNAME conf -- manage.py conf/settings.py conf/wsgi.py conf/urls.py
chmod +x manage.py
workon $PROJECTNAME
# Initialize and use git
git init
git add .
git commit -a -m 'initial commit'
# Show Apache VirtualHost settings:
PROJECTDIR=`pwd`
cat <<VHOST
<VirtualHost *:80>
ServerName ADD_DOMAIN_HERE
WSGIScriptAlias / $PROJECTDIR/conf/wsgi.py
WSGIDaemonProcess $PROJECTNAME python-path=$PROJECTDIR:`virtualenvwrapper_get_site_packages_dir`
WSGIProcessGroup $PROJECTNAME
Alias /images/ $PROJECTDIR/cong/static/images/
Alias /static/ $PROJECTDIR/static/
<Directory $PROJECTDIR/cong/static/images>
Require all granted
</Directory>
<Directory $PROJECTDIR/static>
Require all granted
</Directory>
<Directory $PROJECTDIR>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
VHOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment