If you write <header>
or <footer>
, <link>
or <script>
that defines the reference destination of js or css in html file units, maintainability will decrease.
Is it possible to cite other html files with Layout Dialect
like thymeleaf?
After investigating, django has a concept of template inheritance, so I will use it.
About Django template (html) standardization and inheritance
Describe the common html tag in the reference source, and insert the template tags `{% block <block name>%} ~ {% endblock%}`
in the part that switches depending on the reference source.
parent.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
{% block mainblock %}
(1)
{% endblock %}
</body>
</html>
Describe the template tag ``` {% extends" html file name "%} `` in the reference destination, and the template tag
{% block <block name>%} ~ {% endblock%}
in the content to be switched. Insert ``
For the html file name specified in extends, specify the full path from the templete directory created by django.
child.html
<!DOCTYPE html>
{% extends "pull/parent.html" %} (2)
{% block mainblock %}
(3)
<div>
<span>hello python!!</span>
</div>
{% endblock %}
(1). Area to switch depending on the reference destination. You can specify multiple blocks. (2). Specify the html file to be referenced. (3). Write the area you want to insert in the reference source.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
<span>hello python!!</span>
</div>
</body>
</html>
Recommended Posts