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