4

Currently, I have two html template that extends from a base.html:

page1.html:

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

page2.html:

{% extends 'dashboard/base.html' %}
{% block tittle %} Dashboard2 {% endblock %}
... code ...
Code_block_1
{% endblock %}

Both html share the same Code_block_1.

I was thinking about about creating another html called Code_block_1.html to consolidate this repeating piece of code. Then, insert Code_block_1.html into page1.html and pag2.html. Django only lets you extend once. How do I get around this problem?

Thanks.

1 Answer 1

6

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 %}
Sign up to request clarification or add additional context in comments.

1 Comment

This perfect! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.