Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@brunobord
Last active February 27, 2018 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunobord/48cc208f57eff6fe65555727c9d4e4c8 to your computer and use it in GitHub Desktop.
Save brunobord/48cc208f57eff6fe65555727c9d4e4c8 to your computer and use it in GitHub Desktop.
A Django Debug Middleware class
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