F
F
fantom_ask2020-09-01 14:01:44
Django
fantom_ask, 2020-09-01 14:01:44

How to change templatetags directory?

I have file custom_template_tags.py with code like this

from django import template
from random import randint
register = template.Library()
@register.simple_tag
def random_number():
    return randint(0,999)

and in the template I write {% load custom_template_tags %}

And it will only work if the folder with the files is both in the directory next to manage.py and inside the application folder.
Otherwise I get
is not a registered tag library. Must be one of:

I want to load tags and filters so that there is only one folder next to the manage.py file and all my applications see it, not just one.

I wrote
INSTALLED_APPS = [
 'templatetags.custom_template_tags',
 ]

but it had no effect.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-09-01
@tumbler

The app should contain a templatetags directory, at the same level as models.py, views.py, etc.

documentation
With installed_apps like this, you need a templatetags/custom_template_tags/templatetags/custom_template_tags.py file containing your tags.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question