Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a simple utility for easier debug. When you don't know, which attributes have an object in the template, just apply this filter to it.

This is a simple utility for easier debug. When you don't know, which attributes have an object in the template, just apply this filter to it:

{{object|filter}}

You will see something like that:

['Meta', '__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__metaclass__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__unicode__', '__weakref__', '_changed_data', '_errors', '_get_changed_data', '_get_errors', '_get_media', '_html_output', '_meta', 'add_initial_prefix', 'add_prefix', 'as_p', 'as_table', 'as_ul', 'auto_id', 'base_fields', 'changed_data', 'clean', 'data', 'declared_fields', 'empty_permitted', 'error_class', 'errors', 'fields', 'files', 'full_clean', 'has_changed', 'initial', 'instance', 'is_bound', 'is_multipart', 'is_valid', 'label_suffix', 'media', 'non_field_errors', 'prefix', 'save', 'validate_unique']

Now you can remove the filter and call actual method or attribute.

from django import template
def dir_(value):
'''Just return value's dict, for easier debug.'''
return str(dir(value))
register = template.Library()
register.filter('dir', dir_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment