5.11 Putting It All Together

In Chapter 5, we examined Django views and URL configurations, which make up the Controller of Django’s Model-View-Controller architecture. The Controller acts as the glue between the Model and View. In Django, the Controller receives, selects, processes, and then returns data.

A Django view is any callable that receives an HttpRequest object (with any other additional arguments) and returns an HttpResponse object. Originally, Django recommended using functions as views, but modern Django also provides a canonical way of creating classes to create object views.

To make writing views easier, Django supplies shortcut functions. We saw three shortcuts, starting with get_object_or_404(), which gets an object according ...

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.