Flask學習 三
阿新 • • 發佈:2017-05-18
sky html 文件 deb alt bar javascrip contain sed
使用flask-bootstrap 集成Bootstrap
pip install flask-bootstrap
安裝後即可繼承使用Bootsftrap所有文件的基模版
from flask import Flask,render_template from flask.ext.bootstrap import Bootstrap app = Flask (__name__) bootstrap = Bootstrap(app) @app.route (‘/‘) def index1(): return render_template(‘index.html‘) @app.route (app‘/user/<name>‘) def index(name): return render_template(‘user.html‘,name= name) if __name__ == ‘__main__‘: app.run (debug=True)
{% extends ‘bootstrap/base.html‘ %} {% block title %}Flasky{% endblock %} {% block navbar %} <div class="navbar navbar-inverse" role="navigation">user.html<div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle = ‘collapse‘ data-target=".navbar-collapse"> <span class="sr-only"> toggle navigation</span> <span class="icon-bar"></span> <spanclass="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">Flasky</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li><a href="/">Home</a></li> </ul> </div> </div> {% endblock %} {% block content %} <div class="container"> <div class="page-header"> <h1>Hello,{{ name }}!</h1> </div> </div> {% endblock %}
bootstrap 中scripts和styles塊如果想添加新內容,必須使用super()函數
{% block scripts %} {{ super() }} <script type="text/javascript" src = ‘myscript.js‘></script> {% endblock %}
Flask學習 三