Created
March 11, 2012 23:52
-
-
Save marteinn/2018737 to your computer and use it in GitHub Desktop.
Piston - HTMLEmitter for Django-debug-toolbar
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
# http://tentacles.posterous.com/using-django-debug-toolbar-with-piston | |
from piston.emitters import Emitter | |
from django.http import HttpResponse | |
from django.utils import simplejson | |
from django.core.serializers.json import DateTimeAwareJSONEncoder | |
class HTMLEmitter( Emitter ): | |
def render( self, request ): | |
data = self.construct() | |
json_dump = simplejson.dumps(data, cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4) | |
return HttpResponse('<html><head></head><body><pre>%s</pre></body></html>' % json_dump) | |
Emitter.register( 'html', HTMLEmitter, 'text/html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment