bootstrap, flask.ext.extension, instance of that main class and initialize, register itself with Flask all the changes are in the template. In template the extends directive, to make the template an extension of another template. Similar to class inheritance, bootstrap base contains all elements that make a bootstrap page.
We have emmbedded all the constructs in blocks. Define blocks that override or define parts of base template Block title we put our content. It's up to the template to decide where the content goes.
+25 −11 · 3 files changed
-
flask-blog.py+4 −1 -
templates/macros.html+1 −5 -
templates/weather-average.html+20 −5
@@ -1,7 +1,10 @@ from flask import Flask, render_template +from flask.ext.bootstrap import Bootstrap -app = Flask(__name__) +app = Flask(__name__) +# initialize extension +bootstrap = Bootstrap(app) @app.route('/') def hello_world(): @@ -1,9 +1,5 @@ {% macro weather_cell(value,hl) %} - <td> - {% if hl %}<b>{% endif %} - {{ value }} - {% if hl %}</b>{% endif %} - </td> + <td{% if hl %} class="warning"{% endif %}>{{ value }}</td> {% endmacro %} {% macro weather_row(month, min, max, rain, hl_min, hl_max, hl_rain) %} @@ -1,8 +1,22 @@ +{% extends 'bootstrap/base.html' %} {% import 'macros.html' as macros %} -<h1>Weather Averages</h1> -<h2>{{ city }}</h2> -<hr> -<table> + +{% block title %}Weather Averages for {{ city }}{% endblock %} + +{% block navbar %} + <nav class="navbar navbar-inverse" role="navigation"> + <div class="container"> + <a class="navbar-brand" href="#">Weather</a> + </div> + </nav> +{% endblock %} + +{% block content %} + <div class="container" + <h1>Weather Average</h1> + <h2>{{ city }}</h2> + +<table class="table table-bordered"> <tr> <th>Month</th> <th>Min</th> @@ -18,4 +32,5 @@ highlight['max'], highlight['rain']) }} {% endfor %} -</table> \ No newline at end of file +</table> +{% endblock %} \ No newline at end of file