I use template inheritance in django.
Currently have frame.html and book_detail.html
book_detail.html extends frame.html and I have books_tags.py
# In frame.html
{% load books_tags %}
{% book_list %} # using a tag from books_tags.py
# In books.html
{% extends frame.html %}
{% block content %}
{% book_list %} # I want to use this from books_tags.py also
{% endblock %}
When I try to use book_list from the same books_tags.py, it gives me syntax error. Alternately, when I put {% load books_tags %} inside book_detail.html first, it again still gives me syntax error.
Invalid block tag: 'book_list', expected 'endblock' or 'endblock content'
Is there any way I can use same template tags in multiple inherited templates? Or do I need to create frame_tags.py and book_detail_tags.py with same def in it?
Since default template filters in django works in multiple inheritance, I'm guessing it should work, but don't know how to get by syntax error.
Thank you.
== UPDATE ==
Add template_tag inside {% block content %} in books.html again.
# In books.html
{% extends frame.html %}
{% block content %}
**{% load books_tags %}**
{% book_list %} # I want to use this from books_tags.py also
{% endblock %}
You can use the same template tags in multiple templates, but you have to call {% load books_tags %}
in each file, even if there is an inheritance relationship between them.
See https://docs.djangoproject.com/en/dev/topics/templates/#custom-libraries-and-template-inheritance
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With