[Answer]-How do I adjust the template context given the request object via receiver?

1👍

The context is not an attribute of the request – in fact it is entirely separate from it (*) – so this approach is fundamentally mistaken. Apart from anything else, there is no single “context” – a view may render none, one, or many templates as part of the response, and each template has its own context.

I’m not sure why you can’t just put your did_stuff into the session though. Or, if it needs to be transitory, just add it to the request itself, and check that in the template.

Another possibility would be to get the view to return a TemplateResponse, and write a middleware class that defines a process_template_response method to change the context_data.

(*) although the request can be an item in the context, which happens automatically if you use RequestContext and the request context_processor.

Leave a comment