当网页在Flavik重载时,我如何获得这一现时的变数?
from flask import Flask, render_template
app=Flask(__name__)
import time
from datetime import datetime
from apscheduler.schedulers.background import BackgroundScheduler
current_time = 000
sched = BackgroundScheduler()
def job1():
print( this prints 5 sec )
now = datetime.now()
current_time = now.strftime("%d/%m/%Y %H:%M:%S")
@app.route( / )
def home():
return render_template( home.html , current_time=current_time)
if __name__ == __main__ :
sched.add_job(id= job1 , func=job1, trigger = interval , seconds=5)
sched.start()
app.run(host= 0.0.0.0 )
app.run(debug=True, use_reloader=False)
当我操作时,这部印数5秒半在终端站工作,但当其重新上载时,则在网页上没有更新。 “0”
(I know there are other ways to get the current time on a web page, this is just a simplified example where i want to regularly update variables then have them updated on the html page when the page is loaded.)