Concept Flow - MTV pattern mental model
User Request
URL Dispatcher
View
Template
Response to User
This flow shows how a user request moves through Django's MTV pattern: URL dispatcher sends it to a View, which uses a Template to build the response.
from django.shortcuts import render def my_view(request): data = {'name': 'Alice'} return render(request, 'hello.html', data)
| Step | Action | Input | Output | Next Step |
|---|---|---|---|---|
| 1 | User sends request to URL | /hello | Request object | URL Dispatcher |
| 2 | URL Dispatcher matches URL | /hello | Calls my_view(request) | View function |
| 3 | View processes request | request | Context data {'name': 'Alice'} | Render Template |
| 4 | Template renders HTML | hello.html + context | <html>Hello, Alice!</html> | Send Response |
| 5 | Response sent to user | <html>Hello, Alice!</html> | Page displayed in browser | End |
| Variable | Start | After Step 3 | After Step 4 | Final |
|---|---|---|---|---|
| request | User HTTP request | Passed to view | Used in render | N/A |
| data | N/A | {'name': 'Alice'} | Passed to template | N/A |
| response | N/A | N/A | <html>Hello, Alice!</html> | Sent to user |
MTV pattern in Django: - Model: data layer (not shown here) - Template: HTML layout with placeholders - View: Python function that gets request, prepares data, and calls template Flow: User request -> URL Dispatcher -> View -> Template -> Response View sends data to Template to create dynamic pages.