12.6 Intervening in Control Flow

“Don’t call us. We’ll call you.” The Hollywood principle (inversion of control) is the key to understanding how frameworks like Django operate. Sometimes, however, it becomes necessary to change core parts of Django’s behavior.

In Part I, we never had the chance to actually use the tools Django provides to inject or modify core behavior, but we’ve talked about the two major systems developers use to this end: middleware and context processors. A context processor is a function that modifies a context dictionary of a template before the template is rendered with that data. Middleware are classes that modify the HttpRequest before it arrives to the URL dispatch system and modify the HttpResponse after it is returned ...

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.