Anurag Rana
Anurag Rana

Reputation: 1466

custom template tag library is not getting loaded when placed in a directory with undescore in name

I created a custom tag library file inside a directory name template_tags. I was not getting loaded and was throwing error -

'custom_template_tags' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_static
admin_urls
cache
future
i18n
l10n
log
static
staticfiles
tz

I have __init__.py in folder. I followed all tricks from SO but none worked until I renamed my directory to templatetags. I also tried moving template library outside the folder in app's directory but this also didn't worked.

So I have these questions here
1. Why tag library was not loaded without a directory?
2. When I placed tag library inside directory, why it needed name of directory without underscore in it. Is it done knowingly in django?

Upvotes: 0

Views: 156

Answers (1)

Andrey Shipilov
Andrey Shipilov

Reputation: 2014

From the docs https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#code-layout

The app should contain a templatetags directory, at the same level as models.py, views.py, etc. If this doesn’t already exist, create it - don’t forget the __init__.py file to ensure the directory is treated as a Python package.

Upvotes: 1

Related Questions