python flask how to redirect page code example

Example 1: how to redirect to another route in flask

from flask import Flask, render_templates

app = Flask(__name__)


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


@app.route("/home")
def home:
	return redirect("/", code=302)
  
  
app.run()

Example 2: Howt o get redirected to another page using a button in HTML using Python using Flask

<button type="button" onclick="window.location.href='{{ url_for( 'dataTablePage' , table='Y' ) }}';">Display Table Y</button>