Maternal inheritance of python template language

A native language:

 1. Master and inheritance
        1. Why template and inheritance:
            Extract the common parts of multiple pages and put them in a master.
            Other pages just need to inherit the master.
        2. The specific steps of use:
            1. Extract the common HTML part and put it in the base.html file
            2. In base.html, define the block to distinguish the different parts of each page
            3. In the specific In the page, first inherit the master
            4. Then the block name is used to specify the corresponding position in the replacement master
        
        3. Notes on using master and inheritance:
            1. {% extends 'base.html' %} --> master file :base.html should be quoted
            2. {% extends 'base.html' %} must be placed on the first line of the subpage! ! !
            3. Many blocks can be defined in base.html. Usually, we will define two additional blocks, page-css and page-js
            . 4. What is returned in the corresponding function of view.py is the corresponding sub-page file, is it not base.html?

process:

1: First create a master publish_list page (directly copy the original publish_list page and rename it to publish_list-old)

Two: Extract the different functions in the pages to be operated and put them in the publish_list-zi page

Note: The master here is publish_list, which is to inherit the page. publish_list-zi is the page to be manipulated

Three: Create a logo in the extracted part of the master page {% block page-main % } {% endblock % } 

Four: Write {% extends 'publisher_list' %} in the first line of the subboard page, and then write in front of the extracted page code

{% block  page-main % },最后{% endblock  % } 

Note: string + master html name

Five: Modify the name of the corresponding function render page in views and change it to the name of the sub-page

Six: Open and execute on the sub page  

Note: When opening the execution on the sub-page, be sure to change the page corresponding to the views

 

 

Two: Components: Similar to the usage of the master language, it is generally used for splicing a single function (navigation bar, etc.)

The syntax is {% include %}

 

Three: Static files (js, css, jq, etc.)

Application scenario: For example, the leader wants to change the static path, but there are too many files corresponding to the static path, and it is impossible to modify them one by one. What should I do?

Solution: 1 Find the static file in settings and change it to static999

          2 Find the static path in the master and write {% load static %}

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325856578&siteId=291194637