A website contain header, footer which is common in all pages of the website. So, instead of creating header and footer in all pages, create header, footer in a separate file and include that file in all pages where it is required. In Django, include statement is used to include a file.
Step 1: Create a html file in template folder and name it as header.html, put all contents of header in this file.
Step 2: To call header use the following code:
{% include 'header.html' %}
same way you can use this for footer.
Step 1: Create a html file in template folder and name it as base.html, put header and footer contents in it.
base.html {% include 'header.html' %} {% block content %} {% endblock %} {% include 'footer.html' %}
index.html {% extends 'base.html' %} {% block content %} html file tags, contents goes here. {% endblock %}
urls.py path('', views.home, name='home'), path('', views.about, name='about')
index.html <a href="/home">Home</a> <a href="/about">About</a> or <a href="{% url 'home' %}">Home</a> <a href="{% url 'about' %}">About</a>