如果我覆盖默认的 flask-bootstrap head 和 scripts 块会发生什么?

What would happen if I overwrite the default flask-bootstrap head and scripts blocks?

我正在学习在我的应用程序中使用 flask-bootstrap 扩展。但是当我从 getbootstrap 复制演示 html 代码时,它并没有像官方网站演示的那样工作。所以我在我的基本模板中覆盖了 head 块和 scripts 块,然后它工作得很好。

像这样

{% extends 'bootstrap/base.html' %}

{% block head %}
    (my own head...)
{% endblock %}

{% block scripts %}
    (my own scripts...)
{% endblock %}

这样覆盖bootstrap/base.html自己的头像和脚本可以吗?它会留下什么影响?

它将完全取代基础块。 要保留现有的块但添加自己的块,您应该使用 super():

{% block head %}
    {{ super () }}
    (your head)
{% endblock %}

这将保留原件...您可以在任何其他块中执行相同的操作。 在此处查看更多信息:http://jinja.pocoo.org/docs/2.10/templates/#super-blocks