Tuesday, November 22, 2016

New-style middleware

Hallöchen!

Considering the following old-style middleware class:

class ExceptionsMiddleware:
def process_exception(self, request, exception):
...

I convert this to new-style middleware by inserting two methods:

class ExceptionsMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)
def process_exception(self, request, exception):
...

Is this really correct? Actually, the old way looks more concise to
me. In particular, is there a reason why Django does not provide a
non-deprecated base class for middleware like:

class Middleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)

(I know MiddlewareMixin but it is deprecated.)

Tschö,
Torsten.

--
Torsten Bronger

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/87oa17kxsd.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment