Flask.html變量


1、python – 如何在HTML中顯示變量 - CocoaChina_一站式開發者成長社區.html(http://www.cocoachina.com/articles/77906

 網頁內容保存:

 

這在Flask documentation中已經非常清楚地解釋了,所以我建議您閱讀它以獲得完整的理解,但這是一個渲染模板變量的簡單示例.

存儲在templates / index.html中的HTML模板文件:

<html>
<body>
    <p>Here is my variable: {{ variable }}</p><!-- ZC: 變量在這里 -->
</body>
</html>

簡單的Flask應用程序:

from flask import Flask, render_template

app = Flask('testapp')

@app.route('/')
def index():
    return render_template('index.html', variable='12345')# ZC: 變量在這里

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

運行此腳本並在瀏覽器中訪問http://127.0.0.1:5000/.您應該看到變量的值呈現為12345

 

2

3、

4、

5、

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM