23๐
in settings.py, you should never name the project โmyprojโ explicitely. In INSTALLED_APPS
, just use โmyappโ. Also, you should have this :
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.load_template_source',
)
And be sure to have an __init__.py
in the myapp
folder as well as in templatetags
.
Use manage.py shell
then from myapp.templatetags import myapp_tags
to find out if theres any python error in the myapp_tags.py file.
Also, be sure that myapp_tags.py file name doesnt conflicts with another folder/file in your project.
Hope this helps.
16๐
One thing thatโs tripped me up is that the magic importing of templatetags bypasses the automatic reloading of the development server.
If the following works in manage.py shell
>>> from django.templatetags import myapp_tags
>>>
Then everything is actually working and you just need to reload the development server. If on the other hand you get an ImportError
then something is wrong and you should check your INSTALLED_APPS
, that you have an __init__.py file in the templatetags directory and all the other things suggested in the other answers.
This will probably only apply to a tiny fraction of the people who experience template tag loading problems, but this is the second time Iโve arrived at this question in as many weeks and both times itโs just taken restarting the development server to get things working.
- Rendering spatial data of GeoQuerySet in a custom view on GeoDjango
- Django REST Framework (ModelViewSet), 405 METHOD NOT ALLOWED
- Django migration relation does not exist
- Writable nested serializer in django-rest-framework?
2๐
Some reasons:
- due to error in templatetgs code.
- If you have used model import in templatetags
For #2, for example. If you are doing:
from your_app2.models import model
This will go wrong, so instead above, you should do
from your_project.your_app2.models import model
It worked me this way.
- How to write a Pandas Dataframe to existing Django model
- Django: Tweaking @login_required decorator
- How do I call a model method in django ModelAdmin fieldsets?
- Django-ajax-selects example usage
0๐
I just came across the same problem in Django 2 and realized that the custom template tag files must have unique names across all of your project apps.
- Django redirect() with anchor (#) parameters
- How to prevent user to access login page in django when already logged in?
- Changes made to (static) CSS file not reflecting in Django development server
-3๐
The problem is that nyapp_tags
is not at the top level of an installed project. If you put myproj.myapp.templatetags
in INSTALLED_APPS
, you should be fine.
- Django Login POST hangs when i do HttpResponseRedirect (302)
- How do I get AWS credentials in the AWS ECS docker container?
- What is the different between the get logger functions from celery.utils.log and logging?
- Deploying Django to Elastic Beanstalk, migrations failed
- How to customize django rest auth password reset email content/template