I was researching on this for quite a bit. I have a use case where the same task has to be performed in all functions of a controller, is there a way to by default call that function in the controller? Aside from creating a method and calling it in each function.
Currently that is what I am doing, but would like to avoid that if possible.
You need to write middleware class, implementing
process_request(self, request)with functionality that must be executed before view method will be called. Don’t forget to add class name to MIDDLEWARE_CLASSES in your settings file.