-
-
Save Akash1362000/ea1effe5f4bac4b531d5ab484814ee24 to your computer and use it in GitHub Desktop.
Class based Middleware in Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExampleMiddleware: | |
def _init_(self, get_response): | |
self.get_response = get_response | |
def _call_(self, request): | |
# Code that is executed in each request before the view is called | |
response = self.get_response(request) | |
# Code that is executed in each request after the view is called | |
return response | |
def process_view(request, view_func, view_args, view_kwargs): | |
# This code is executed just before the view is called | |
def process_exception(request, exception): | |
# This code is executed if an exception is raised | |
def process_template_response(request, response): | |
# This code is executed if the response contains a render() method | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment