[Django]-Reuse same "block" of html in multiple django templates

5👍

Simply create another HTML file called code_block_1.html and then inside both page1.html and page2.html use include like this:

<!-- page1.html -->

{% extends 'dashboard/base.html' %}
{% block tittle %} Dashboard1 {% endblock %}
... code ...
{% include 'code_block_1.html' %}
{% endblock %}


<!-- page2.html -->

{% extends 'dashboard/base.html' %}
{% block tittle %} Dashboard2 {% endblock %}
... code ...
{% include 'code_block_1.html' %}
{% endblock %}
👤nik_m

Leave a comment