原创

Flask(6)-Jinja2模板使用(Url_for)

<!--  index.html  -->
<!DOCTYPE html>
<html lang="zh-en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>index</title>
</head>
<body>
<h1>Index</h1>

<!--  和url_for一样,可以传递参数  -->
<p><a href="{
  { url_for('login',ref='/p/',id='9') }}">登录</a></p>

</body>
</html>
<!--  login.html  -->
<!DOCTYPE html>
<html lang="zh-en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
</head>
<body>
<h1>登录页</h1>
</body>
</html>
# app.py
from flask import Flask, render_template, url_for

app = Flask(__name__)

@app.route("/index/")
def index():
    return render_template("index.html")

@app.route("/login/")
def login():
    return render_template("login.html")


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

 

 

正文到此结束
评论

登录后才能发表评论 登录/注册

0评论
  • 还没有评论,快来抢沙发吧!