2017-04-03 54 views
0

訪問以下數據的一些可能方法是什麼?解析燒瓶模板中的數據2級別(render_template)

我從數據庫的數據查詢:all_data

@app.route('/testing',methods=['GET','POST']) 
def testing(): 
    all_data=session.query(xxx).all()  # <----------this is my sql data I get from some query 
    ..... 
    render_template("template1.html", data=all_data) 

在template1.html

  • 並先後獲得all_data
  • 它有一個鏈接到template2.html(使用燒瓶url_for)

問題是在template2.html中,如何訪問all_data?無論如何,我可以配置做到這一點?

感謝

回答

0

你也會有這使得template2.html燒瓶路線 - 所以在該路線你需要做同樣的SQL查詢來獲取all_data

@app.route('/other',methods=['GET','POST']) 
def testing(): 
    all_data=session.query(xxx).all() 
    return render_template("template2.html", data=all_data) 
+0

render_template還可以在HTML模板內工作嗎? 或者我需要將其重定向到一個定義,然後在def for template2.html中再次執行查詢? –

+0

url_for可以採取複雜的參數嗎?例如url_for(測試,數據= all_data)和all_data是一個python dictinoary –