Installing Django

  • Step-by-step guide to installing Django and setting up your development environment.
  • Why This Lesson Is Important?

    Before learning Django:

    • Python must be installed correctly

    • Django must match Python version

    • Virtual Environment is mandatory for professional projects

    This lesson prepares students for real-world Django development.

    1. Installing Python

    Django is a Python-based framework, so Python installation is the first step.

    Installing Python on Windows

    Steps:

    1. Go to python.org

    2. Download Python 3.x (latest stable)

    3. IMPORTANT: Check ☑ Add Python to PATH

    4. Click Install Now

    Code Example: Check Python Installation (Windows)

Verify Python Installation

Confirms Python is installed correctly

python --version
  • Installing Python on Ubuntu (Linux)

    Steps:

    1. Open Terminal

    2. Update system

    3. Install Python

    Code Example: Install Python on Ubuntu

Python Installation on Ubuntu

Installs Python using apt package manager

sudo apt update
sudo apt install python3 python3-pip -y

Check Python Version (Ubuntu)

python3 --version
  • 2. Installing Django

    After Python is installed, Django can be installed using pip.

    Installing Django on Windows

    Steps:

    1. Open Command Prompt

    2. Use pip to install Django

    Code Example: Install Django (Windows)

Django Installation Using pip

Installs Django globally on Windows

pip install django

Verify Django Installation

django-admin --version
  • Installing Django on Ubuntu

    Steps:

    1. Open Terminal

    2. Use pip3 to install Django

    Code Example: Install Django on Ubuntu

Django Installation on Ubuntu

Installs Django using pip3

pip3 install django

Verify Django Version

django-admin --version
  • 3. Virtual Environment Setup (Very Important)

    What is a Virtual Environment?

    A Virtual Environment:

    • Isolates project dependencies

    • Prevents version conflicts

    • Is industry best practice

    👉 Each Django project should have its own environment

    Why Virtual Environment is Required?

    Problem

    Without venv

    With venv

    Package conflict

    Version control

    Project isolation


    Virtual Environment Setup on Windows

    Steps:

    1. Create project folder

    2. Create virtual environment

    3. Activate environment

    Code Example: Create Virtual Environment (Windows)

Create Virtual Environment on Ubuntu

Creates isolated environment using venv

sudo apt install python3-venv -y
python3 -m venv myenv
  • Activate Virtual Environment (Ubuntu)

    source myenv/bin/activate

    4. Install Django Inside Virtual Environment (Best Practice)

    Once venv is activated:

    Code Example: Install Django in Virtual Environment

Django Installation in Virtual Environment

Installs Django for project only

pip install django

Verify Installation

django-admin --version