Here, we will explain about inheritance of django's HTML template.
You can inherit the underlying HTML template file by using ʻextends. You can create a block to be rewritten by setting
{% block block name%}`. It can also be used to load custom CSS and javascript files.
base.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>page title</title>
</head>
<body>
{% block content %}
{% endblock content %}
</body>
</html>
sample.html
{% extends 'base.html' %}
{% block content %}
{% endblock content %}
You can include HTML files as part of a page by using ʻincludes`.
sidebar.html
<div class="sidebar">
<p>Side bar</p>
</div>
sample.html
{% extends 'base.html' %}
{% block content %}
<div class="main-content">
<p>Main content</p>
</div>
{% includes 'sidebar.html' %}
{% endblock content %}
Here, I explained the application of django's HTML template. We will continue to add content as needed.
Recommended Posts