5.9 Class-Based Views

Warning!

This section deals with Python methods and HTTP methods. I will refer to Python methods simply as methods and to HTTP methods as HTTP methods, typically referring to the actual HTTP method in capitals (such as the HTTP GET method or the HTTP OPTIONS method).

Any Python callable that accepts an HttpRequest object as argument and returns an HttpResponse object is deemed a view in Django. So far, we’ve stuck exclusively to using Python functions to create views. Prior to Django 1.3, this was the only recommended way to create views. However, starting in version 1.3, Django introduced a class to allow developers to create view objects.

Django introduced a class to create view objects because coding the class for ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.