码迷,mamicode.com
首页 > 其他好文 > 详细

条件判断

时间:2018-02-18 17:43:39      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:div   html   flask   index   use   find   deb   end   route   

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>

 

条件判断

标签:div   html   flask   index   use   find   deb   end   route   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!