load and static Tags
When we want to use some static resources on the page, such as pictures, js, css. At this time, we will use the static tag.
For example, display a local picture in the page.
Operation steps:
A. create a new folder to hold static resources, such as static. To distinguish it from the following static tags, the static name is used here
b. load the statistics folder into the python search path.
c. use the {% load static%} load tag at the beginning of the page to load the static tag.
d. use {% static 'image path'} where the image is to be displayed
{% static 'picture path'} indicates that the static in the note syntax is fixed and cannot be changed.
Template inheritance
When we browse a website, we find that most of the pages are the same. At this time, we can use inheritance in html files to reduce tedious work and code.
- Define motherboard
- Inherited motherboard
Syntax: {% extends' base.html '%}
{% extends 'publisher_list.html' %} {% block main %} <table class="table table-bordered"> <thead> <tr> <th>Serial number</th> <th>id</th> <th>Name of Publishing House</th> <th>operation</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>1</td> <td>Beijing Press</td> <td> <a class="btn btn-danger" href="">delete</a> <a class="btn btn-info" href="">edit</a> </td> </tr> <tr> <td>2</td> <td>2</td> <td>Shanghai Publishing House</td> <td> <a class="btn btn-danger" href="">delete</a> <a class="btn btn-info" href="">edit</a> </td> </tr> <tr> <td>3</td> <td>3</td> <td>Tianjin Publishing House</td> <td> <a class="btn btn-danger" href="">delete</a> <a class="btn btn-info" href="">edit</a> </td> </tr> </tbody> </table> {% endblock %}
assembly
Common page contents such as navigation bar and footer information can be saved in a separate file, and then imported according to the following syntax where they need to be used.
Syntax:
{% include 'navbar.html'%} inserts the entire file.