Redirecting to another page with button click in Python-flask

Dul’s Blog

--

buttons, and redirects with flask

Hi, so first refer my tutorial “How to add separate templates for separate pages in flask”. Inside the templates folder there is an index.html which contains the instructions for the arrangement of layouts in the homepage or index page. code of index.html.

<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="{{ url_for('static', filename='home.css') }}">
</head>
<body>
<h2>Vehicle info Dashboard</h2><p align="center"><a href=vmd_timestamp ><button class=grey style="height:75px;width:150px">vmd timestamp</button></a></p></body>
</html>

This is how the homepage looks like.

Here I have added the button inside a paragraph element, and inside this same paragraph element which contains the button, there is an a href, anchoring element, which leads to the vmd_timestamp, you can add the name of the route page which you wish to lead.

app.py code, in my case I am directing index or home page to vmd_timstamp via a button click event as described above.

from flask import Flask, request,render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')@app.route('/vmd_timestamp')
def vmd_timestamp():
return render_template('vmd_timestamp.html')

Thanks for reading. Have fun coding !!!!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Dul’s Blog
Dul’s Blog

Written by Dul’s Blog

Graduate student at University of Moratuwa

No responses yet

Write a response