Last active
February 27, 2018 11:21
-
-
Save brunobord/48cc208f57eff6fe65555727c9d4e4c8 to your computer and use it in GitHub Desktop.
A Django Debug Middleware class
This file contains 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
import warnings | |
class DebugMiddleware(object): | |
""" | |
Dummy debug middleware. For Developers only. | |
Simply add it at the end of your MIDDLEWARE_CLASSES, in your | |
:file:`local.py`, for example, like this:: | |
MIDDLEWARE_CLASSES += ['peopleask.toolkit.middlewares.DebugMiddleware'] | |
""" | |
def __init__(self, *args, **kwargs): | |
warnings.warn( | |
"DebugMiddleware is activated. BEWARE! this class is for developers only!", # noqa | |
RuntimeWarning | |
) | |
super(DebugMiddleware, self).__init__(*args, **kwargs) | |
def process_request(self, request): | |
# e.g: | |
# print(request) | |
pass | |
def process_response(self, request, response): | |
# e.g. | |
# print(request) | |
# print(response) | |
# **MANDATORY**: LEAVE THIS RETURN HERE, OTHERWISE YOUR | |
# APPLICATION WON'T WORK | |
return response | |
def process_exception(self, request, exception): | |
# e.g.: | |
# print(request) | |
# print(exception) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment