很遗憾,jinja2不能使用多继承
如何进行多层继承?
比如base.html为母模板
blogBase.html为blog模块的模板,并以base.html为模板
blogBase1.html为以blogBase.html为模板的HTML文件
即base.html->blogBase.html->blogBase1.html
一句话:使用super()函数
不多说了,上代码
以title为例:
base.html:
<title>{% block title %}{% endblock %}-tigerLee的blog</title>
blogBase.html:
{% block title %}我的博客{% endblock %}
blogBase1.html:
{% block title %}{{ super() }}{% endblock %}
此时页面的title显示为:我的博客-tigerLee的blog
如果你里面什么也没有,即:
{% block title %}{% endblock %}
则会显示
-tigerLee的blog
(变红是Markdown的标记问题,不用管它)
如果你
blogBase1.html:
{% block title %}{{ super() }}haha{% endblock %}
则会显示:我的博客haha-tigerLee的blog
这下明白了吧,祝大家学习开心!