Flask includes the redirect
function for redirecting to any url. Futhermore, you can abort a request early with an error code with abort
:
from flask import abort, Flask, redirect, url_for
app = Flask(__name__)
@app.route('/')
def hello():
return redirect(url_for('hello'))
@app.route('/hello'):
def world:
abort(401)
By default a black and white error page is shown for each error code.
The redirect
method takes by default the code 302. A list for http status codes here.