Twenty-one: jinja2 of template inheritance

 

 

Template inheritance can have in common some code to extract into the parent template, other characteristics of the times required to file template inheritance

In jinja2 in use extends to inherit defined template, {% block location name%} {% endblock%} placeholder to

 

We need to define a parent template

 

Other html template you can have all inherited base modules

 

block inheritance only position, not inherit the default content, if you want to inherit the contents of the module to change the parent template in the specified module, use super () method

 

Another block in the calling code: {{self.block can be obtained by name ()}}

 

Precautions

1, sub-template to be inherited from the parent template in the first line of code, or the code before the code will fail to inherit

2, sub-template if you want to implement your own code, to be put in the corresponding block, or they will not render that template in response to the sub-rendering content, only the contents of the parent template into position inside reserved

 

Guess you like

Origin www.cnblogs.com/zhongyehai/p/11784765.html