Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Created August 30, 2011 14:33
Show Gist options
  • Save specialunderwear/1181028 to your computer and use it in GitHub Desktop.
Save specialunderwear/1181028 to your computer and use it in GitHub Desktop.
template tags for inspecting variables inside templates
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