Updating HTML Page Using Flask Without Reloading

Viewed 25

How would I update an html page using Flask? I'm trying to make a clock in Flask but I don't know how to update the webpage without reloading it. The get_time function gets the time in a formatted string.

main.py

app = Flask(__name__)

@app.route('/')
def home():
  data = get_time()
  return render_template('index.html', data=data)
    
app.run(host='0.0.0.0', port=8080)

index.html

<!doctype html>
<html>
  <head>
  <title>Clock</title>
  </head>
  <body>
    <h1> {{ data[0] }} </h1>
    <h1> {{ data[1] }}:{{ data[2] }}:{{ data[3] }} </h1>
  </body>
</html>
0 Answers
Related