Use of the django master page, django
The master page is used to process the same part of the html page to avoid repeated
1. Add a master page
Add the templates folder in the same directory as the manage. py file to save the html file on the master page.
2、 basbase.html, html is as follows:
<! DOCTYPE html>
Use block for placeholder
3. Use the master page on a specific page
{% extends 'Base.html' %}{% block content%}This is ChildPageContent{% endblock %}
4. Because the master page and child page are not in the same APP, you need to configure the path in the settings. py file of the master module. You do not need to configure the path in the same app,
Configure the path of the master page in DIRS under TEMPLATES
The specific configuration is as follows:
TEMPLATES = [{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': ['django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages',], }, },]
The final page effect is as follows: