Use of the django master page, django

Source: Internet
Author: User

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:

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.