Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand the inheritance and inclusion of boards in django

Shulou Source: shulou.com Published: 2022-06-02 01:51:37 10月04日 Update

How to understand the inheritance and inclusion of the board in django, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

The inheritance application scenario of the template, for example, the financial news page structure of a website is composed of three parts: the top, the body and the bottom. The page structure of entertainment news is the same as that of financial news, except that the content of the middle text is different. This uses the inheritance of the template.

Using the method of template inheritance, first write a base template [base_html], then other templates inherit the structure of the base template, and finally override the block in the base template. The advantage of this is that the code can be reused, easy to maintain, and reduce the amount of code.

As shown in the following figure, first write the basic page structure in base.html, then inherit the structure of the base template with {% extends' base template path'%} on other pages, and finally rewrite the block content in the base template.

The template contains application scenarios, for example, each page will use a navigation bar, you can first write a navigation page, and then include the navigation bar you wrote on other pages, which is equivalent to a full copy, and the page you use cannot modify the content of the containing page.

As shown below:

After reading the above, have you mastered how to understand the inheritance and inclusion of boards in django? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Template page foundation structure content news method navigation midboard code scene more text finance problem application helpless for this reason three major reasons Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft NVidia Shulou Technology Xiaomi