[Django]-Django: Invalid filter

23👍

First off remove the semicolon after your replace.

Do you have a file called __init__.py (this is suppose to have 2 underscores before and after init, hard to format in editor.) under the templatetags directory?

Here is a good page with lots of info if you haven’t looked yet.

http://docs.djangoproject.com/en/dev/howto/custom-template-tags/

38👍

Just for reference, I solved the problem by moving

{% load ... %}

from the base template to the concrete template.
See also this post https://stackoverflow.com/a/10427321/3198502

22👍

I was nearly going nuts with this problem and none of the above answers helped.

If you have several apps, make sure that the file names containing your custom tags/filters are unique, prefereablyapp_name_filters.py. Otherwise Django will only load the custom filters from the app it finds matching first!

👤Meilo

3👍

To avoid loading the module in each template using {% load MODULE_NAME %}, you can add it as a 'builtin' in settings.py:

TEMPLATES = [
    {
        'OPTIONS': {
            ...
            ,
            'builtins': [
                ...
                'APP_NAME.templatetags.MODULE_NAME',
                ]
        },
    },
]

Leave a comment