0

So far in our code we have implemented Django built-in signals for handling user login, logout, and failed login as well as db actions with pre-save, post_save and post_delete signals. I am looking to maintain consistency by performing some operations on the http response after a request has been made using signals. However, I do not see any built-in signal that grants access to the response object. I am aware of the request_finished signal but this does not seem to provide access to the response object. I have successfully achieved what I need using Django's process_response function in middleware but was wondering if there was a way I could maintain consistency and use a signal here as well.

We are using Django 2.2 and DRF 3.8.2

bbmhmmad
  • 372
  • 1
  • 6
  • 21
  • Signals are not the place to do this - if you want to modify all responses you should do so with middleware. – solarissmoke Dec 07 '19 at 06:44
  • Also, signals on model-actions get messy when the application gets bigger, it could be better to just override the `.save()` and `.delete()` methods on the model. I personally only use signals if I have to hook into all models, or hook into a third party library. I agree about middleware. If you change the response, that's the way to go, if it's for all views. – Denis Cornehl Dec 07 '19 at 07:07
  • it would only be for one of the views (for now) so im using `decorator_from_middleware` on that particular view – bbmhmmad Dec 07 '19 at 08:04

0 Answers0