The include statement renders another template and outputs the result into the current template. The included template has access to context of the current template by default.
#home/views.py
from django.shortcuts import render
# Create your views here.
def index(request):
kdict = {
'siteTitle':'Khmer Web',
'pageTitle': 'Home',
'message': '<b>ស្វាគមន៍មកកាន់ទំព័រដើម!</b>'
}
return render(request,'base.html',context={'data':kdict})
<!--home/templates/header.html-->
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>{{ data.siteTitle }} | {{ data.pageTitle }}</title>
<link rel="stylesheet" href="{% static 'styles/base.css' %}" />
<link rel="stylesheet" href="{% static 'fonts/setup.css' %}" />
<link rel="icon" href="{% static 'images/siteLogo.png' %}" />
</head>
<body>
<!--home/templates/body.html-->
<p>
{% for key,value in data.items %}
<p>{{ value|safe }}</p>
{% endfor %}
</p>
<!--home/templates/footer.html-->
</body>
</html>
{% include 'header.html' %}
{% include 'body.html' %}
{% include 'footer.html' %}