Question

I thought I understood the WSGI specification. So I'm looking at this Django module https://github.com/django/django/blob/master/django/middleware/locale.py and I just don't see how it's an implementation of a wsgi middleware as pep0333 explains it.

I was expecting a signature somewhere, such as

def __call__(self, environ, start_response)

as well as a small routine that would call another application and handle its returned value.

Could someone explain where's the server bit and where's the application in this middleware?

Was it helpful?

Solution

Django middleware is a little different then what you are thinking. It sits inside of the django stack. Through django middleware you have access to each step of the request and response a user makes/recieves.

https://docs.djangoproject.com/en/dev/topics/http/middleware/?from=olddocs

This just takes place within django. WSGI handles processing the request and returning the response but django gives you hooks to modify it once it hits django.

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