Question

Does the Middleware framework hook the request object before it is sent to the urlconf?
Also, does this hook happen after it goes through WSGIHandler?
So, just in respect to these three "layers", is it the order in which request is processed?
WSGIHandler --> Middleware --> urlconf

Was it helpful?

Solution

The WSGI handler is what coordinates all requests to your Python web application; technically, your WSGI handler is the code that calls the rest of the Django request/response process. So everything is "going through" your WSGI handler, if you are using one.

When a request comes in, Django will construct a request object and successively pass it to each piece of registered middleware. This request object is then passed to the view, which is expected to return a response object that may be serialized to a valid HTTP response. Since the url conf simply maps a pattern to a view function, it doesn't matter when it is matched; ultimately, the corresponding view is called after the middleware. So you may make assumptions in your view code that any registered middleware has already been executed.

Googling around produced this high level view of the process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top