Install Django on Ubuntu

Installing Django on Ubuntu

Today i am going to show how to setup or install Django environment on Ubuntu. I will be concentrating only on python 3 version. Django is web application framework written in python, It Uses MVT (Models, Views, Templates) Concept .

We will be installing django in an isolated environment but why? simple because we do not want django packages to mess with os python libraries, we will be using pip to install packages and virtualenv to create virtual environments.pip is a package management system used to install and manage software packages written in Python. Now open your terminal and follow this commands

Install python3 Pip

sudo apt-get install python3-pip

Install Virtualenv

sudo pip3 install virtualenv

Create new directory for your project

mkdir -p Code/Django/myapp
cd Code/Django/myapp

Create new Virtual Environment we will call it py3

virtualenv py3

Once you run above command new directory py3 will be created. Now We need to activate our new py3 environment

source py3/bin/activate

your prompt will be changed to (py3) Code/Django/myapp

Now Install Django. Notice we are not running pip3 command, we will just run pip inside virtualenv

pip install django

Once Django is installed, you can check the version by

django-admin --version

Lets start new project call makeinindia

django-admin startproject makeinindia
cd makeinindia

Lets start new app blog

python startapp blog

Now we will start the server

python runserver

Finally done, Whenever you want to leave the virtual environment just run to deactivate

Dont forget to run this command Every time you want to work with your Django app

cd Code/Django/myapp
source py3/bin/activate