Articles → DJANGO → Template Inheritance In Django

Template Inheritance In Django

What Does Template Inheritance Mean?

How To Implement Template Inheritance In Django?

  1. Create a base template.
  2. Inherit the base template

Create A Base Template

    <title>this is the test title</title>
    <h1>Title of the page</h1>
    <div id="container">{% block content%} {% endblock content%}</div>

Inherit The Base Template

{% extends "base.html" %}
{% block content%}
    This is the home page
{% endblock content%}

{% extends "base.html" %}
{% block content%}
    Welcome to Gyan Sangrah: A one stop shop for people preparing for technical interviews. Gyansangrah is an online resource comprising all the possible questions you may face during your technical interview round. Gyansangrah also provides you with live examples to make concepts easier to understand.
{% endblock content%}

from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.

def home(request):
    return render(request, 'home.html', {})

def about(request):
    return render(request, 'about.html', {})


Picture showing the output of Template inheritance in Django
Click to Enlarge

Posted By  -  Karan Gupta
Posted On  -  Wednesday, June 19, 2019


Your Email Id  
Query/FeedbackCharacters remaining 250