Session Overview

  • Introduction to Django
  • Virtual Environment
  • Django Installation
  • Project Creation
  • Application Creation
  • Project Structure

Introduction to Django

Django is a high-level Python Web Framework used to build secure, scalable and maintainable web applications.

Applications Commonly Built Using Django
  • Blog Websites
  • E-Commerce Applications
  • Content Management Systems
  • Social Media Platforms
  • Business Management Systems
Features of Django
  • Built using Python.
  • Fast Development.
  • Built-in Admin Panel.
  • Secure Authentication System.
  • ORM for Database Operations.
  • Supports MySQL, PostgreSQL and SQLite.
Why Django?

Django follows the "Don't Repeat Yourself (DRY)" principle and provides many built-in features that reduce development time.

Note: In this training we will build a complete Blog Application using Django, MySQL and Bootstrap.

Virtual Environment

A Virtual Environment is an isolated Python environment used to install project-specific packages.

It helps avoid conflicts between packages used by different projects.

Create Project Folder
mkdir DjangoTraining

cd DjangoTraining
Create Virtual Environment
python -m venv env
Activate Virtual Environment (Windows)
env\Scripts\activate
Output
(env) C:\DjangoTraining>
Deactivate Virtual Environment
deactivate
Important: Always activate the virtual environment before installing Django or running the project.

Django Installation

After activating the Virtual Environment, we can install Django using pip.

Install Django
pip install django
Verify Installation
django-admin --version
Output
6.0.6
View Installed Packages
pip list
Sample Output
Package   Version
--------- -------
Django    6.0.6
pip       26.1.2
sqlparse  0.5.5
asgiref   3.11.1
Important: Ensure the virtual environment is activated before running the installation command.

Project Creation

A Django Project is the main container that holds settings, URLs and applications.

Create Project
django-admin startproject BlogProject
Move Inside Project Folder
cd BlogProject
Run Development Server
python manage.py runserver
Output
Starting development server at
http://127.0.0.1:8000/
Open Browser
http://127.0.0.1:8000
Django Welcome Screen

If installation and project creation are successful, Django displays its default welcome page.

Stop Server
CTRL + C
Note: The development server is used only during development and testing.
Commands Used So Far
python -m venv env

env\Scripts\activate

pip install django

django-admin startproject BlogProject

cd BlogProject

python manage.py runserver

Application Creation

A Django Application is a module that performs a specific task within a project.

Create Application
python manage.py startapp blog
Project Structure After Creating Application
BlogProject
│
├── BlogProject
│
├── blog
│
└── manage.py
Important: Multiple applications can exist inside a single Django project.
Important: Register Application

After creating an application, we must register it in the project's settings.py file.

If the application is not registered, Django will not be able to use its templates, models, admin configuration and other resources.

File Location
trainingproject/settings.py
Add Application Name
INSTALLED_APPS = [

    'demo',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

]
Result: Django can now discover:
  • Templates
  • Models
  • Admin Configuration
  • Migrations
Project vs Application

Project is the complete website.
Application is a specific feature or module inside the website.

Example:
  • Project → Blog Website
  • Application → Blog Module
  • Application → User Management Module
  • Application → Product Module

Project Structure

After creating a project and application, Django generates several files and folders automatically.

Project Structure
BlogProject
│
├── BlogProject
│   ├── settings.py
│   ├── urls.py
│   ├── asgi.py
│   ├── wsgi.py
│   └── __init__.py
│
├── blog
│   ├── admin.py
│   ├── apps.py
│   ├── models.py
│   ├── tests.py
│   ├── views.py
│   └── migrations
│
└── manage.py
Important Files
File Purpose
manage.py Execute Django Commands
settings.py Project Configuration
urls.py URL Routing
views.py Application Logic
models.py Database Models
admin.py Admin Panel Configuration
Note: We will learn settings.py, urls.py, views.py and models.py in detail in upcoming sessions.

Quick Revision

Virtual Environment
  • Create → python -m venv env
  • Activate → env\Scripts\activate
  • Deactivate → deactivate
Django Installation
  • pip install django
  • django-admin --version
  • pip list
Project Commands
  • startproject
  • runserver
  • CTRL + C
Application
  • startapp
  • Specific Module
  • Inside Project
Project vs App
  • Project = Complete Website
  • App = Feature / Module
  • Multiple Apps Possible
Important Files
  • settings.py
  • urls.py
  • views.py
  • models.py

Assignment

Complete the following tasks:
  1. Create a new folder named DjangoPractice.
  2. Create and activate a Virtual Environment inside the folder.
  3. Install Django and verify the installed version.
  4. Create a Django Project named StudentPortal and run the development server.
  5. Create an Application named students inside the project.