Created
August 30, 2011 14:33
-
-
Save specialunderwear/1181028 to your computer and use it in GitHub Desktop.
template tags for inspecting variables inside templates
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 import template | |
register = template.Library() | |
@register.simple_tag | |
def props(obj): | |
result = [] | |
for key in dir(obj): | |
try: | |
result.append("%s -> %s<br/>" % (key, getattr(obj, key))) | |
except Exception as e: | |
result.append("%s -> %s<br/>" % (key, e)) | |
return "".join(result) | |
@register.simple_tag | |
def classof(obj): | |
return obj.__class__.__name__ | |
@register.simple_tag | |
def dictof(obj): | |
return str(obj.__dict__) | |
@register.simple_tag | |
def metaof(obj): | |
return str(obj.__class__.__class__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment