[PYTHON] Django HTML Template # 2

Introduction

Here, we will explain about inheritance of django's HTML template.

HTML template inheritance

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 %}

Template embedding

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 %}

Summary

Here, I explained the application of django's HTML template. We will continue to add content as needed.

Recommended Posts

Django HTML Template # 2
Django HTML template
Django # 2 (template)
Django Template notes
Django Template Tips
Django template file organization
Flask HTML template settings
Django
Make the model a string on a Django HTML template
Template registration from Django Bootstrap
Show Django ManyToManyField in Template
template
Common html to rent with Django
Make a filter with a django template
[Tips] How to do template extends when creating HTML with django
How to do arithmetic with Django template
django update
Django memorandum
django search
Django installation
Django Summary
Django test
(Note) Template file search order in Django
Django Note 5
Django hands-on
Touch django
django notes
Django Summary
Django basics
Django Shoho
WEB application development using Django [Template addition]
Django defaults
Django + Docker
Django Glossary
Django search
(For myself) Django_1 (Basic / Hello World / Template)
Install Django
Django: References
Django Note 1
Edit Django shift table HTML and CSS
Django note 3
Django note 2
Resolve Angural JS and Django template conflicts
Django startup
Write a short if-else for Django Template
Django notes
Django NullCharField
Django template reads Makdown and reStructuredText written in an external file as HTML
In Django, display batch (command) results sequentially in HTML
Specify the view URL in your Django template
Run a Python file from html using Django