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

参数传递

时间:2018-02-18 16:22:56      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:def   lang   set   rom   参数   temp   pos   from   name   

# coding=utf-8
from flask import Flask, render_template
from models import User

app = Flask(__name__)


# 参数传递之字符串传递
@app.route("/user")
def hello_world():
    content = "kevin durant"
    return render_template("index.html", content=content)

# 参数传递之对象传递
@app.route("/user2")
def get_user():
    user = User(1, "lebron jams")
    return render_template("index2.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>
    <h1>{{ content }}</h1>
</body>
</html>

#index2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>hello, you are {{ user.user_name }}</h1>
</body>
</html>

 

参数传递

标签:def   lang   set   rom   参数   temp   pos   from   name   

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

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