Introduction

Django is a Python web framework — a big library of pre-built pieces for routing URLs, talking to a database, rendering HTML, and handling user accounts, so a real web application doesn't start from a blank file.

Why use a framework at all

Every dynamic website needs roughly the same scaffolding: a way to match a URL to some code, a way to read and write data in a database, a way to turn that data into HTML, and a way to know who's logged in. You could write all of that yourself, but Django already has, and its pieces are designed to work together — which is the whole appeal of a framework over hand-rolling each part.

Installing Django

Django is a regular Python package, installed with pip like any other:

Terminal
pip install django
Output
Successfully installed django-5.0.1

Starting a project

The django-admin command, installed alongside the package, scaffolds a new project directory:

Terminal
django-admin startproject mysite
cd mysite
python manage.py runserver
Output
Watching for file changes with StatReloader
Django version 5.0.1, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Visiting http://127.0.0.1:8000/ in a browser at this point shows Django's default "The install worked successfully" page — confirmation the project is wired up correctly, before you've written a single line of your own view code.

The Model-View-Template pattern

Django organizes an application around three roles: a model defines what your data looks like and talks to the database, a view is a Python function (or class) that decides what happens for a given request, and a template turns data into the HTML actually sent back to the browser. The rest of this course builds up each of these one at a time, starting with the files a fresh project generates.

Note: Django calls this pattern "MVT," not the more familiar "MVC" — the mapping is close (view ≈ controller, template ≈ view) but not identical, and it's worth not overthinking the naming difference. What matters is the actual division of responsibility, which you'll see directly in the next lesson.