سؤال

I am really confused as to how could I load a custom tag filter from another app. I have a similar problem like this Load custom template tag from another application? And, I am doing it the same way, but still it doesnt load up and I am getting this error :

TemplateSyntaxError at /
'fillme_tag' is not a valid tag library: Template library fillme_tag not found, tried django.templatetags.fillme_tag,django.contrib.staticfiles.templatetags.fillme_tag,fillme.templatetags.fillme_tag

I have the app in settings installed app too. I have tried loading it using various ways as mentioned below: {% load fillme_tag %} {% load fillme.fillme_tag %} #filleme is appname.

The structure is as follows:

my_project:
    app1:
        templates:
            index.html (this is where i want to load custom tag)
        views.py
        __init__.py
    fillme:
        templatetags:
            __init__.py
            fillme_tag.py (the tag lib)
        __init__.py

----- contents of fillme_tag.py ----

from django import template

register = template.Library()

@register.filter(name='demotag')
def demotag(value):
    return value
هل كانت مفيدة؟

المحلول

It seems you missed fillme/__init__.py. Add it and this must work:

{% load fillme_tag %}

UPDATE

As error message said it couldn't open fillme_tag as it was invalid Library. My guess is you have a typo somewhere.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top