a、b兩個視圖,分別返回a的頁面和b的頁面
重定向:redirect
重定向到路由:請求/a/時,重定向到/b/
重定向到視圖函數:url_for(“函數名“),訪問/a/時,重定向到函數b()
主動返回404:abort
# coding:utf-8
from flask import Flask, render_template, redirect, url_for, abort
app = Flask(__name__)
# 訪問/help/時主動返回404
@app.route('/help/')
def req_help():
abort(404)
@app.route("/a/")
def a():
# return render_template("a.html")
# return redirect('/b/')
return redirect(url_for('b')) # 根據視圖函數名稱綁定路由地址
@app.route("/b/")
def b():
return render_template("b.html")
if __name__ == '__main__':
app.run(debug=True)