Skip to content Skip to sidebar Skip to footer

Django 1.10: "new Style" Middleware Equivalent Of `process_request()`

How would one create 'new style' middleware, which fulfills an equivalent implementation to using the process_request() hook with the 'old style'? I've already adapted pre 1.10 mid

Solution 1:

Here an example...

classTimeStampMiddleware(object):

    def__init__(self, get_response):
        self.get_response = get_response

    def__call__(self, request):
        request.timestamp = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')

        response = self.get_response(request)
        return response

Now you can get the timestamp in every request from yours views! (is only an example)

Post a Comment for "Django 1.10: "new Style" Middleware Equivalent Of `process_request()`"