Articles → DJANGO → Template inheritance in Django

Template inheritance in Django






What does template inheritance mean?







How to implement template inheritance in Django?











Create a base template




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





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",{})   



Output



Click to Enlarge


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

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250