6👍
From the documentation (emphasis mine):
process_template_response()
is called just after the view has finished executing, if the response instance has arender()
method, indicating that it is aTemplateResponse
or equivalent.
You state that you’re using django.http.shortcuts.render
, whose documentation reads:
Combines a given template with a given context dictionary and returns an
HttpResponse
object with that rendered text.Django does not provide a shortcut function which returns a
TemplateResponse
because the constructor ofTemplateResponse
offers the same level of convenience asrender()
.
Thus render
returns a HttpResponse
, not a TemplateResponse
, and as noted above, process_template_response
is only called for TemplateResponse
s.
You either need to change your view to return TemplateResponse
, instead of using the render
shortcut, or perform your logic elsewhere. I think your logic could be implemented in a context processor instead of middleware.