Answer the question
In order to leave comments, you need to log in
How to organize template inheritance?
I have a base template base.html, header.html is inherited from it, almost all the rest are inherited from it. I pass styles and scripts through inheritance like this:
in base.html
<script type="text/javascript" src="{% static 'js/base.js' %}"></script>
{% block scripts %}{% endblock %}
{% block scripts %}<script type="text/javascript" src="{% static 'js/header.js' %}"></script>{% endblock %}
<div>{% block username %}{% endblock username %}</div>
{% block username %}<a href="{% url 'accounts:profile' %}">{{ user.username }}</a>{% endblock username %}
Answer the question
In order to leave comments, you need to log in
In the heirs of header.html
{% block scripts %}
{{ block.super }}
<script type="text/javascript" src="{% static 'js/footer.js' %}"></script>
{% endblock %}
{{ block.super }}
, the contents of the parent block will be substituted. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question