Search code examples
djangodjango-templatesdjango-filters

Django - 'helpers' is not a valid tag library


When following the Custom template tag & filters tutorial, I get this error:

'helpers' is not a valid tag library: Template library helpers not found, tried django.templatetags.helpers,django.contrib.staticfiles.templatetags.helpers,django.contrib.admin.templatetags.helpers

I saw a lot of questions about this same issue, but none of the following actions solved it.

Folder structure:

container/
  module/
    templatetags/
      __init__.py
      helpers.py
    templates/
      ...
    ... (views, models, ...)
  system/
    ... (urls, settings, ...)

In system/settings.py, the module is included:

INSTALLED_APPS = (
    ...
    'module',
)

My helper source doesn't trigger any syntax or import error from the django shell:

from django import template
register = template.Library()

@register.filter
def myhelper(value):
    return value

Finally, the template that calls myhelper is simply:

{% load helpers %}
{{ "hello"|myhelper }}

Why doesn't it work ?


Solution

  • Thanks to the sergzach's idea, I was able to make my filter work by renaming its file from helpers.py to somethingelse.py.


    Edit

    Django has its own helpers for generating the admin page. That would be the cause of the naming conflicts.