Skip to content

Instantly share code, notes, and snippets.

@marteinn
Created March 11, 2012 23:52
Show Gist options
  • Save marteinn/2018737 to your computer and use it in GitHub Desktop.
Save marteinn/2018737 to your computer and use it in GitHub Desktop.
Piston - HTMLEmitter for Django-debug-toolbar
# 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