21👍
I faced this problem to.what i did was just stop the server run and just run it again.It seems that django does not initialize tags (or resources in general) while running the server.hope it helps.
9👍
According to django documentation:
Development server won’t automatically restart after adding the templatetags module, you will need to restart your server before you can use the tags or filters in templates.
So, to resolve the issue, you need restart development server.
Source: https://docs.djangoproject.com/en/3.0/howto/custom-template-tags/#code-layout
- Docker Django could not connect to server: Connection refused
- Django – annotate() – Sum() of a column with filter on another column
2👍
Just for a reminder, when using django under Windows, it is necessary to restart the development server (python.exe manage.py runserver) in at least two situations, which are:
- when a new templatetag was created in an app
- when static files were modified in the ‘app/static/app/’ folder
Hope this helps
- How to provide $ to third-party, external jQuery plugins in Django admin
- Is Django Asyc Views an ajax replacement?
- Having a separate database for django-admin in django
- Using urls names in views
1👍
I faced the same problem, but reloading the server doesn’t work.
So I solved it by this:
at project/setting.py I wrote the next, at TEMPLATE I registered libraries:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
'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',
],
'libraries': {
'my_tags': 'app.templatetags.blog_tags',
}
},
},
]
And the server restarted by itself.
- Integrating django-haystack with django-rest-framework?
- Gunicorn not responding
- Push notifications with django and GCM
- Django: Giving validation error feedback on a form after a post redirect get
0👍
In Django 3.1 i solved it putting my py file inside templatetags folder inside my app. As the docs said. custom template tags.
The py file must have register = template.Library()
myapp/templatetags/mytags.py
in settings i have myapp inside INSTALLED_APPS array
Then in my template file
{% load mytags %}
- Django admin – how to get all registered models in templatetag?
- How to use Channel instead of Group when using django channels?
- Django admin filter using F() expressions
- Django loading data from fixture after backward migration / loaddata is using model schema not database schema
- Having a separate database for django-admin in django