Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading custom tag filters from another app

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
like image 446
Maverick Avatar asked Jul 06 '13 21:07

Maverick


People also ask

How many arguments does the tag method uses for registering custom tags?

Registering the tag The tag() method takes two arguments: The name of the template tag – a string. If this is left out, the name of the compilation function will be used. The compilation function – a Python function (not the name of the function as a string).

What {% include %} does?

{% include %} Processes a partial template. Any variables in the parent template will be available in the partial template. Variables set from the partial template using the set or assign tags will be available in the parent template.

What are Django template tags?

Django Code The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client.


1 Answers

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.

like image 153
shalakhin Avatar answered Oct 10 '22 13:10

shalakhin