Skip to content Skip to sidebar Skip to footer

Encountered Unknown Tag 'load'.?

I want to add some custom-template-tags.But, {% load userfilters %} => 'load' tag is not working. settings.py # project/settings.py TEMPLATES = [ { 'BACKEND': 'dja

Solution 1:

There is no load tag in Jinja2, and filters work a little differently too (they're just functions).

templatetags/*.py is a Django Templates convention, and Jinja2 doesn't use them at all.

You'll want to register your filters where you set up your environment:

def environment(**options):
    env = Environment(**options)
    env.globals.update({
        'static': static,
        'url': reverse,
    })
    env.filters.update({
        'a': a,
    })
    return env

Another option is to use the django-jinja template backend instead of Django's built-in Jinja2 backend; it's a little more featureful and supports templatetags style loading out of the box.


Post a Comment for "Encountered Unknown Tag 'load'.?"