Bootstrap 的初始化作用
初始化Bootstrap邮破,即:
bootstrap = Bootstrap(app)
但是之后并未用到 bootstrap 這個(gè)實(shí)例對(duì)象,此處實(shí)例化的作用,很可能就是為了尋址到 base.html 文件的所在,畢竟安裝位置非常深,并且很有可能不同情況下安裝目錄是不同的塘淑。
參考博客:關(guān)于flask-bootstrap的一些理解
初始化的位置
最開始的時(shí)候受 Flask Web 開發(fā)第三章的誤導(dǎo),將初始化語句放置到了最后一行蚂斤,導(dǎo)致出錯(cuò)存捺。
將初始化放置在開頭之后便解決了這個(gè)問題。
from flask.ext.bootstrap import Bootstrap
from flask import Flask, render_template
app = Flask(__name__)
bootstrap = Bootstrap(app)
#...
@app.route('/')
def index():
return render_template('index.html')
@app.route('/user/<name>')
def user(name):
return render_template ('user.html',name = name)
if __name__ == '__main__':
app.run(debug=True)
安裝目錄
安裝目錄要明確橡淆,第一次運(yùn)行時(shí)看到當(dāng)前文件夾中有所運(yùn)行的文件,但其實(shí)是同名的空文件母赵。
這種詭異的Bug逸爵,能找到也是運(yùn)氣好。