从另一个应用加载自定义标记过滤器

时间:2023-01-11 19:22:00

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.

我也在应用程序设置安装了应用程序。我尝试使用以下提到的各种方式加载它:{%load fillme_tag%} {%load fillme.fillme_tag%} #filleme是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 ----

----- fillme_tag.py的内容----

from django import template

register = template.Library()

@register.filter(name='demotag')
def demotag(value):
    return value

1 个解决方案

#1


4  

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

看来你错过了fillme / __ init__.py。添加它,这必须工作:

{% load fillme_tag %}

{%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.

由于错误消息表示无法打开fillme_tag,因为它是无效的库。我猜你在某个地方有错字。

#1


4  

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

看来你错过了fillme / __ init__.py。添加它,这必须工作:

{% load fillme_tag %}

{%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.

由于错误消息表示无法打开fillme_tag,因为它是无效的库。我猜你在某个地方有错字。