Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap templates auto-generated?

I'm having trouble setting up Flask-bootstrap. From the official documentation, it seems like all I have to do is apply the Bootstrap constructor to my app, and the templates will be automatically created. So I tried this:

from flask import Flask
from flask.ext.bootstrap import Bootstrap

app = Flask(__name__)
Bootstrap(app)

@app.route('/')
def index():
    return '<h1>Where is Bootstrap?</h1>'

if __name__ == '__main__':
    app.run(debug=True)

When I run it, no new directories are created and I find no base templates anywhere. Am I missing a critical step? Is there some directory to be created first (I tried creating templates and static and setting the permissions to 777 but that didn't help)? Or perhaps the base templates are first to be generated from the command line?

like image 631
ankush981 Avatar asked Sep 25 '26 06:09

ankush981


1 Answers

The base templates are part of the Flask-Bootstrap package you installed. You extend the boostrap base template and override the blocks in it to create a page with a standard layout. You still need to write bootstrap related markup. This is explained right in the docs you linked to.

my_project/templates/my_page.html:

{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}

{% block navbar %}
<div class="navbar navbar-fixed-top">
  <!-- ... -->
</div>
{% endblock %}

{% block content %}
  <h1>Hello, Bootstrap</h1>
{% endblock %}
like image 170
davidism Avatar answered Sep 28 '26 10:09

davidism



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!