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):
| Part | Job | Example |
|---|---|---|
| Model | Describes and stores data | A Course table with name and fee |
| View | Python logic that handles a request | Get all courses and pass them on |
| Template | HTML that shows the data | A page listing the courses |
A URL pattern connects each web address to a view.
- The browser asks for
/courses/. - Django checks the URL patterns and finds the matching view.
- The view gets data from the model (the database).
- The view sends the data to a template.
- 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
mkdir mysite
cd mysite
python -m venv venvActivate it:
Example
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activateYour 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
pip install django
python -m django --version5.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
from django.utils.text import slugify
print(slugify("Web Development Course 2026"))
print(slugify("Graphic Designing & UI/UX"))web-development-course-2026 graphic-designing-uiux
Exercise
Exercise
In Django's MVT pattern, which part holds the HTML?
