1.
Flask.redirect(location, statuscode, response)

location: URL be redirected
statuscode: defaults to 302
response: used to instantiate response

standardized status code−
    HTTP_300_MULTIPLE_CHOICES
    HTTP_301_MOVED_PERMANENTLY
    HTTP_302_FOUND
    HTTP_303_SEE_OTHER
    HTTP_304_NOT_MODIFIED
    HTTP_305_USE_PROXY
    HTTP_306_RESERVED
    HTTP_307_TEMPORARY_REDIRECT

example:

vi templates/login.html
<html>
   <body>

      <form action = "/check" method = "POST">

         <p>ID <input type = "text" name = "Name"/></p>
         <p><input type = "submit" value = "Login"/></p>

      </form>

   </body>
</html>
vi login.py
from flask import Flask, redirect, url_for, render_template, request

# Initialize the Flask application
ap = Flask(__name__)

@ap.route('/login')
def login():
   return render_template('login.html')

@ap.route('/check', methods = ['POST', 'GET'])
def check():

   if request.method == 'POST' and request.form['Name'] == 'admin':
      return redirect(url_for('success'))

   return redirect(url_for('login'))

@ap.route('/success')
def success():
   return 'logged in successfully'

if __name__ == '__main__':
   ap.run(host='0.0.0.0')
python login.py

2.
abort(code)

Code parameter values-
    400 − for Bad Request
    401 − for Unauthenticated
    403 − for Forbidden
    404 − for Not Found
    406 − for Not Acceptable
    415 − for Unsupported Media Type
    429 − Too Many Requests

example:

#make some modify in login.py
vi login.py
from flask import Flask, redirect, url_for, render_template, request, abort

@ap.route('/check', methods = ['POST', 'GET'])
def check():

   if request.method == 'POST':
      if request.form['Name'] == 'admin' :
         return redirect(url_for('success'))
      else:
         abort(401)

   return redirect(url_for('login'))