UNIT 05 · TOPIC 07
Django Views
A view handles a request, performs application logic and returns a response such as rendered HTML or JSON.
The idea
Django Views, simply explained
A view handles a request, performs application logic and returns a response such as rendered HTML or JSON.
01
See the big picture
How the idea flows
Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.
02
Everyday connection
Real-life example
↗
A restaurant menu view loads today's dishes and returns a page to the visitor.
03
Learn by doing
Python code example
PYTHONExample
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {'name': 'Asha'})Expected result
Renders home.html with name='Asha'Try it: Change one value in the code, predict what will happen, then run it and compare your answer.
04
Keep this in mind
Key takeaways
- A view handles a request, performs application logic and returns a response such as rendered HTML or JSON.
- Think of a real problem where django views could save time or organize information.
- Test small changes and read the result carefully before moving to a bigger program.
Quick self-check
Can you explain it in your own words?
What is the main idea of Django Views?
A view handles a request, performs application logic and returns a response such as rendered HTML or JSON.
Where could you see this idea in everyday life?
A restaurant menu view loads today's dishes and returns a page to the visitor.
