flask之后端傳值給前端


服務端代碼:

from flask import Flask, request, render_template

app = Flask(__name__)


@app.route('/')
def index():
    variable={"name": "張三"}
    return render_template("index.html", variable=variable)


@app.errorhandler(404)
def miss(e):
    return render_template('404.html'), 404


@app.errorhandler(500)
def error(e):
    return render_template('500.html'), 500


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5002, debug=True)

html頁面使用

        <p>{{variable.name}}</p>


免責聲明!

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



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