I'd like to call a function in my view or any module for that matter and have it update the response body.
My initial thinking is to implement a process_response
middleware to update the response body, and set up a callback that receives signals sent in my function calls, but when I try, the receiver never fires (I've tested the singal/receiver outside of the middleware class/module and it works fine.
Example:
# in module that defines the signal
module.signal.send(msg='this is a message to append on the response body')
# in view or model
signal.connect(callback)
# in middleware.py
def callback(self, sender, *kwargs):
self.body_text = kwargs.pop('msg')
def process_response(self, request, response):
response.body = response.body + self.body_text
return response