重定向 redirect
Status Code 302: 重定向
redirect(location=""),location支持:
- loaction 可以是本地路由
- 绝对url
from flask import redirect, url_for
@app.route("/hello/<string:username>/<string:message>")
def hello(username, message):
return f"<h1>hello {username}: {message}</h1>"
@app.route("/hi")
def hi():
return f"<h1>hello everybody</h1>"
@app.route("/login")
def login():
# return redirect(location="/hi") # 本地路由
# return redirect(url_for("hi"))
# return redirect(url_for("hello", username="jack", message="good morning")) # 本地路由带参数
return redirect("http://www.baidu.com") # 绝对url
if __name__ == '__main__':
app.run(debug=True)