Django Tutorial menu

Django Introduction

Django is a Python framework that gives you ready-made tools for building websites.

What is Django?

  • A web framework: a set of tools and rules for building web apps
  • Written in Python and free to use
  • First released in 2005, now very mature and stable
  • Includes a database layer (ORM), an admin panel, user logins, forms and security

How Django Works: MVT

Django follows a pattern called MVT (Model, View, Template):

PartJobExample
ModelDescribes and stores dataA Course table with name and fee
ViewPython logic that handles a requestGet all courses and pass them on
TemplateHTML that shows the dataA page listing the courses

A URL pattern connects each web address to a view.

  1. The browser asks for /courses/.
  2. Django checks the URL patterns and finds the matching view.
  3. The view gets data from the model (the database).
  4. The view sends the data to a template.
  5. The template creates the HTML that goes back to the browser.

What You Need

  • Python 3.10 or newer. Check with python --version
  • A code editor such as VS Code
  • Basic Python knowledge: variables, functions, lists and dictionaries

Create a Virtual Environment

A virtual environment is a private folder of Python packages for one project. It keeps projects from disturbing each other.

Example

bash
mkdir mysite
cd mysite
python -m venv venv

Activate it:

Example

bash
# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate

Your terminal now shows (venv) at the start of the line.

Activate the virtual environment every time you open a new terminal to work on the project.

Install Django

Example

bash
pip install django
python -m django --version
Output
5.2.7

Your version may be newer. Everything in this tutorial works with Django 5.

Django Is Python

Because Django is plain Python, you can try parts of it in the Python shell. For example, Django's helper for making URL-friendly text:

Example

python
from django.utils.text import slugify

print(slugify("Web Development Course 2026"))
print(slugify("Graphic Designing & UI/UX"))
Output
web-development-course-2026
graphic-designing-uiux

Exercise

Exercise

In Django's MVT pattern, which part holds the HTML?

Learn Django with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp