0

I am learning to use flask-bootstrap extension in my app. But when I copied demo html codes from getbootstrap, it didn't work as the official site demonstrated. So I overwrote the head block and scripts block in my base template, then it works nicely.

Like this

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

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

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

Is it okay to overwrite bootstrap/base.html’s own head and scripts like this? What effects it will leave?

Bicheng
  • 687
  • 8
  • 20

1 Answers1

1

it will completely replace the base blocks. To keep the existing blocks but add your own to them, you should use super():

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

This will keep the originals... you can do the same in any other blocks. See more here: http://jinja.pocoo.org/docs/2.10/templates/#super-blocks

Daniel da Rocha
  • 887
  • 13
  • 26
  • I know this will completely replace the base blocks. What I want to confirm is that this "completely replacement" will not leave bad effects or bugs. So, is it OK? – Bicheng Apr 25 '18 at 06:57
  • well, it depends on what's on `bootstrap/base.html`, just do it to see what happens. Initially I would say it would break some things.... – Daniel da Rocha Apr 25 '18 at 08:47