I used process_request and process_response functions in django middleware in order to log the requests before hitting the viewset. But, I get Internal Server Error. I don\'t
The problem is the return Response()
in your middleware methods.
If you return a response in the process_request method, then Django will not call the view. You probably don't want to return anything here.
You should return a response from the process_response method. You probably want to return the original response from the view (response
) here. If you return a different response (e.g. Response(...)
), then Django will return this to the user instead of the response from the view.
class MyMiddleware():
def process_request(self, request):
print "xxxxx"
def process_response(self, request, response):
print "xxxxx"
return response
See the Django docs for more information about what you should return from each middleware method.
I fixed the issue. It's because the response object returned by process_response doesn't have actual response. I modified it to following and it worked.
class MyMiddleware():
def process_request( self, request ):
print "xxxxx"
return None
def process_response( self, request, response ):
print "xxxxx"
return response