12.3.1 Views
A view is any Python callable that takes an HttpRequest instance and returns an HttpResponse object.
Typically, views are either (1) a function or (2) an object instantiated by a subclass of View. Developers could build their own class for providing the basic behavior of a view, but doing so turns out to be tricky. To best avoid security problems, developers typically stick to using View when building class-based views (CBVs) because it is safer and quicker.
The advantage of using a function for a view is the simplicity of a function. The advantage of using a CBV is better adherence to HTTP. Similar behavior is available to developers when programming function views thanks to the require_http_methods decorator (and its siblings, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access