Class Library
A class for registering template tags and filters. Compiled filter and
Declaration
class Library
source linkDocumentation
template tag functions are stored in the filters and tags attributes.
The filter, simple_tag, and inclusion_tag methods provide a convenient
way to register callables as tags.
Methods
▶ def filter(self, name=None, filter_func=None, **flags) Register a callable as a template filter. Example:
@register.filter
def lower(value):
return value.lower()
▶ def inclusion_tag(self, filename, func=None, takes_context=None, name=None) Register a callable as an inclusion tag:
@register.inclusion_tag('results.html')
def show_results(poll):
choices = poll.choice_set.all()
return {'choices': choices}
▶ def simple_tag(self, func=None, takes_context=None, name=None) Register a callable as a compiled template tag. Example:
@register.simple_tag
def hello(*args, **kwargs):
return 'world'
▷ def tag(self, name=None, compile_function=None)
Reexports