Skip to content

Instantly share code, notes, and snippets.

@leetrout
Created June 12, 2014 14:09
Show Gist options
  • Save leetrout/ab136dbfb97f8ee1d309 to your computer and use it in GitHub Desktop.
Save leetrout/ab136dbfb97f8ee1d309 to your computer and use it in GitHub Desktop.
from django.core.conf import settings
class DbgResponse(object):
def process_response(self, request, response):
"""Add html, head, and body tags so debug toolbar will activate."""
if request.GET.get('dbg') and settings.DEBUG:
cnt = response.content
if '<body>' not in cnt:
response.content = '<html><head></head><body>%s</body></html>' % cnt
if 'content_type' in response._headers:
hdr = response._headers['content_type']
response._headers['content_type'] = (hdr[0], 'text/html')
return response
@jdunck
Copy link

jdunck commented Jun 13, 2014

I forked and improved this to handle gzip'd responses and to set Content-Length based on the HTML wrapping.

https://gist.github.com/jdunck/5f8c516c8620d976d51a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment