Setup of django, virtualenv and dependencies using pip

By | 24th November 2014

Recently I started working on a django project which is exciting at the same time challenging. I thought its good time to document some of the steps to deploy the project and these are the steps to follow.

System requirements

In a typical debian system run the following commands to get required packages before we start the setup.
#apt-get install python-pip python-virtualenv libpq-dev

Setup of virtualenv

To run a virtualenv follow these steps.
1. select a directory to install custom python.
virtualenv /home/user/virtual
2. Run the following command to start the environment.
source /home/user/virtual/bin/activate
3. To deactivate
deactivate

Courtesy: http://docs.python-guide.org/en/latest/dev/virtualenvs/

Install specific version of django

To install a specific version of django
pip install django=1.6.2
This is the working version of django. 1.6 is not working.

Install dependencies

1. Install the dependencies of pflat
pip install south django-chosen django-datetime-widget psycopg2

Additional tweaks

Create a db and user. follow this link https://bhuvan.wordpress.com/2014/11/20/adding-postgresql-user-and-db-quick-steps/

Running python manage.py syncdb will show the error
FATAL: Peer authentication failed for user "tom"
to fix the error edit the file /etc/postgresql/9.4/main/pg_hba.conf. Make sure you are editing the right postgresql version file. Go down and change the line

local   all             postgres                                peer

to

local   all             postgres                                md5

After editing the file restart postgresql.

Sync DB and migrate

Run these 2 commands to sync the database and migrate data if any from root of the project.
python manage.py syncdb
python manage.py migrate