Views and URLs
Route requests to views.
What is a View?
A Django view is a function (or class) that takes a web request and returns a web response. Views hold your page logic and live in an app's views.py.
from django.http import HttpResponse
def home(request):
return HttpResponse('Hello, world!')
print('A view takes request, returns response')The request Argument
Every view receives a request object holding details about the incoming request: method, GET/POST data, user, and more.
from django.http import HttpResponse
def info(request):
return HttpResponse('Method: ' + request.method)
print('request carries the incoming data')All lessons in this course
- Projects and Apps
- Models and Migrations
- Views and URLs
- The Django Admin