Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
Besides putting my_templatetag.py
inside app_name/templatetags
, make sure you restart the Django development server (or ensure it restarted itself) every time you modify template tags. If the server does not restart, Django won't register the tags.
From Django 1.9, you can load those new tags/filters in settings like this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'app.apptemplates.load_setting',
],
'libraries':{
'my_templatetag': 'app.templatetags.my_templatetag',
}
},
},
]
If you have templatetag dir in your project dir (not in an app dir), then above method is recommended.
Example-
Quoting: https://docs.djangoproject.com/en/3.2/howto/custom-template-tags/#:~:text=It%20also%20enables%20you%20to%20register%20tags%20without%20installing%20an%20application.
Make sure you are not missing any of the following steps:
Create a folder called "templatetags" at the same level as models.py and views.py in your application folder
Your application must be in the INSTALLED_APPS in settings.py
The templatetags folder must have __init__.py
Restart the django server
In my case the problem was, I was using {% load filter_method_name %}
I had to change to {% load filename %}
I then had to restart the server.
you have to manually stop the development server and start it again, so Django can identify the new template tags