参数传递

# 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>

 

posted @ 2018-02-18 15:54  道高一尺  阅读(136)  评论(0编辑  收藏  举报