Created
August 18, 2015 15:34
-
-
Save joeyfigaro/1c1e5acbeb7092b1e559 to your computer and use it in GitHub Desktop.
Inspect vars directly in your views (https://djangosnippets.org/snippets/743/)
This file contains hidden or 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 import template | |
from django.template.defaultfilters import linebreaksbr | |
from django.utils.html import escape | |
try: | |
from django.utils.safestring import mark_safe | |
except ImportError: # v0.96 and 0.97-pre-autoescaping compat | |
def mark_safe(x): return x | |
from pprint import pformat | |
def rawdump(x): | |
if hasattr(x, '__dict__'): | |
d = { | |
'__str__':str(x), | |
'__unicode__':unicode(x), | |
'__repr__':repr(x), | |
} | |
d.update(x.__dict__) | |
x = d | |
output = pformat(x)+'\n' | |
return output | |
def dump(x): | |
return mark_safe(linebreaksbr(escape(rawdump(x)))) | |
register = template.Library() | |
register.filter('rawdump', rawdump) | |
register.filter('dump', dump) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment