Skip to content

Instantly share code, notes, and snippets.

@fabiosussetto
fabiosussetto / gist:c534d84cbbf7ab60b025
Last active December 2, 2023 01:11
Enable Django toolbar for JSON responses
class NonHtmlDebugToolbarMiddleware(object):
"""
The Django Debug Toolbar usually only works for views that return HTML.
This middleware wraps any JSON response in HTML if the request
has a 'debug' query parameter (e.g. http://localhost/foo?debug)
"""
@staticmethod
def process_response(request, response):
if request.GET.get('debug'):