Template structure optimization - Inheritance

The benefits of using inheritance: all part of the same sub-pages using a html file to store in the sub-pages in through inheritance

This stored html file, like this page will only write a few lines of code, which greatly reduce the amount of code

1. The overall project structure

 

2. view.py (do view function) and in the urls.py (do mapping)

 3. These three sub-page (index.html, company.html, school.html) difficult to communicate the love of code stored in base.html page

5. Next to inherit base.html in the three sub-pages

6. Then run django, you can see the effect

 

Guess you like

Origin www.cnblogs.com/ifdashui/p/11803374.html