Created
June 12, 2014 14:09
-
-
Save leetrout/ab136dbfb97f8ee1d309 to your computer and use it in GitHub Desktop.
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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