首页 > 其他 > 详细

条件判断

时间:2018-02-18 17:37:32      阅读:193      评论:0      收藏:0      [点我收藏+]
from flask import Flask, render_template


app = Flask(__name__)

@app.route("/user/<user_id>")
def get_user(user_id):
    user = None
    if int(user_id) == 1:
        user = "kevin durant"
    return render_template("index.html", user=user)


if __name__ == __main__:
    app.run(debug=True)

#index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
</head>
<body>
{% if user %}
    hello, you are {{ user }}
{% else %}
    sorry, do not find your name
{% endif %}
</body>
</html>

 

条件判断

原文:https://www.cnblogs.com/themost/p/8452942.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!