"'tag' is not a registered tag library. Must be one of" in a Django app

Viewed 10985

I added my simple tags to my file in template tags. My first tag is visible and it works properly, but the second one does not work. I receive information ''deposit_earn' is not a registered tag library. Must be one of:' after I added tags to my template {% load deposit_earn %}.

My tag file looks like this:

@register.simple_tag()
def multiply(number_instalment_loans, rrso, balance):
    rrso_percent = rrso/100
    return round(discounted_interest_rate(12, number_instalment_loans, rrso_percent, balance))

@register.simple_tag()
def deposit_earn(period, interest, balance):
    interest_percent = interest/100
    equals = balance * interest_percent * period / 12
    return round(equals)

Why is my first tag working and not the second one? I tried to reset the server after registering the tags, but it did not help.

3 Answers

https://docs.djangoproject.com/en/2.2/howto/custom-template-tags/

you should import templatetags file name, not method name

polls/
    __init__.py
    models.py
    templatetags/
        __init__.py
        poll_extras.py
    views.py

let say multiply and deposit_earn inside of poll_extras.py

then in your template, you just need call poll_extras

{% load poll_extras %}

{{ something|multiply }}
or
{{ something|deposit_earn }}

You might wanna restart the server after following all the jizz given in the documentation... It really made me spet about 10 minutes trying to figure out what the problem was when all I had to do was restart the server.

It worths mentioning that, if the templatetags directory doesn't exist, after creating it and don't forget to include the empty __init__.py script so the directory will be treated as Python package. Otherwise you still get Django error page.

Related