0Pricing
Python Academy · Lesson

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

  1. Projects and Apps
  2. Models and Migrations
  3. Views and URLs
  4. The Django Admin
← Back to Python Academy