process_request is called before Django determines which view should process the request (therefore, this is only the request parameter).
process_view is called after Django determines which view will process the request, but before calling this view. It will have access to the request object along with the view that will handle it and the parameters that will be passed to this view.
Whenever you need to know the view that will be used for the request, you can use process_view . A good example for this is the Django CSRF Middleware process_view , which will not provide CSRF protection if the csrf_exempt decoder is present on the view that the request is intended for:
def process_view(self, request, callback, callback_args, callback_kwargs): [...] if getattr(callback, 'csrf_exempt', False): return None [...]
Adrian ghiuta
source share