What is Django? (MVT)
A Python framework that gives you almost everything to build a website — fast and securely.
What you will learn
- Understand what Django is
- Learn the MVT pattern
- See why Django saves time
Batteries included
Django is a Python web framework that comes with almost everything you need: URL routing, a database layer (an ORM — Object-Relational Mapper, a tool that lets you use the database with normal Python instead of writing SQL — Structured Query Language, the special text language databases normally use — by hand), a ready-made admin panel, user login, forms and security — all built in. You write less code and ship faster.
The MVT pattern
| Part | Job |
|---|---|
| Model | Your data (a Python class = a database table) |
| View | The logic (a Python function that handles a request) |
| Template | The HTML the user sees |
The flow: a request hits a URL → Django calls a view → the view uses a model to get data → it passes that data to a template → the finished HTML is sent back.
A concrete walk-through. Imagine your blog has two posts saved: "Hello Django" and "My second post". A visitor opens the address /posts in their browser. Here is what each MVT part does:
- The visitor’s browser requests the URL
/posts. - Django matches that URL and runs the matching view (a Python function called, say,
post_list). - The view asks the Model for the data — "give me all posts" — and gets back the two saved posts.
- The view hands those two posts to a Template (an HTML file) that loops over them.
- The finished HTML — a page listing "Hello Django" and "My second post" — is sent back and shown in the browser.
Note: So with two posts in the database, the visitor ends up seeing a page that lists both titles. Each MVT part did one job: URL found the view, the view got the data from the model, and the template turned it into the page.
Tip: Everything you learned in Python — variables, functions, classes — is used here. Django models are just Python classes; views are just Python functions.
Q. In Django’s MVT, what holds your data (a database table)?
✍️ Practice
- Draw the Django request flow for “show a list of posts”.
- Match Model/View/Template to what each does.
🏠 Homework
- Explain MVT in your own words with a simple analogy.