Python Web Framework

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Install Python, pip and virtualenv

  • Windows: Please find in from Home Page

  • Ubuntu: Please find it from Ubuntu setup

  • Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip.

  • You can simply use pip or pip3 install any package you need.


Install django

  • create a folder virtualenvs within the location of python 3

  • create a new virtualenv named django18

  • Activate the new virtual env

  • Install Django 1.x.x (LTS version)

    cd  /path/to/python3
    cd  virtualenvs
    virtualenv django18
    cd django18
    which python
    pip install django==1.x.x

Create django project

  • SET PATH in current command promp

  • Navigate to workspace folder

  • Create new django project

  • Start the app

    SET PATH=c:\apps\python3\virtualenvs\django18\Script;%PATH%
    which django-admin
    cd c:\ws\python\django\
    django-admin startproject demo
    cd demo
    python runserver

Create a new app module

python startapp main

Create a new db

following commands are just tested in django 1.8

python syncdb 
python makemigrations new_app 
## migrate 
pyrhon sqlmigrate new_app 0001 
## migrate 
python migrate new_app 0001

use python shell Model API

python shell
>>> from XXX.models import ModelClass
>>> ModelClass.objects.all()
>>> ModelClass.objects.get(pk =1 )
>>> ModelClass.objects.filter( fieldName1="abc")
>>> mc = new ModelClass.( fieldName1 = "abc", fieldName2="def", fieldName3 = 3 )
>>> mc = ModelClass.objects.get(pd=1)
>>> mc.delete()    


pip install virtualenv

pip3 install virtualenv

cd ~

mkdir .envs

## create python2 env
virtualenv -p /usr/bin/python2.7 py2env

virtualenv -p /usr/bin/python3.4 py3env

cd py2env 
source bin/activate

## Check python path 
which python

## Exit

Activate virtual environment need to use source instead of executing sh file