15.4.4 Displaying FlatPage Objects via Middleware

As discussed in Chapter 9 and Chapter 12, middleware is a class that modifies HttpRequest and HttpResponse objects. These classes receive the HttpRequest before it reaches the view, and then receive the HttpResponse that the view has created, as shown in Figure 15.1. The set of middleware classes receive the HttpResponse objects in the reverse order from HttpRequest objects: the first class to receive the HttpRequest will be the last to receive the HttpResponse object. The utility of middleware is that it allows information to be added to every webpage (this is how the cross-site request forgery [CSRF] token works).

Figure 15.1: MVC Diagram with Middleware

Prior to Django 1.4, the flatpages ...

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.