Use custom directory for "templatetags"
This is possible. Just add location of your templatetags.py
or templatetags directory to Django settings.py
into OPTIONS
in TEMPLATES setting.
In my case I put my templatetags in the libs/
directory that is located in project root dir.
You have two options, builtins
or libraries
:
TEMPLATES = [{
...
'OPTIONS': {
...
'builtins': [
'libs.templatetags'
],
# or as @x-yuri pointed out, you can put them in `libraries`
'libraries': {
'my_tags': 'libs.templatetags',
},
}
}]
If you use builtins
, it is available everywhere and you don't need to use {% load %}
for that.
If you use libraries
you need to use {% load my_tags %}
.