Forums

[flask] datetime not constantly updating

I built a flask app that has a feature that depends on the time. The problem is that the time only updates if I reload the app. I am using the datetime module in my script, and it works, but it seems to store the time from when the whole webapp is reloaded instead of when i go to the URL and view the page. Is there a way to get the flask script to update the current time when I visit the page? Like is this a cache thing or just the way flask works?

Is this because you are getting the current datetime at the module level and not within a function?

See if this is relevant.

Yes! I was calling datetime from a global variable and using the variable in my function.

I tried the same thing in IDLE, and calling datetime in a variable freezes the datetime. I never realized it because normal scripts run when I run them, with flask, it is running all the time!

So I made a function with a variable inside calling datetime and just run that function when it is needed inside of flask. brilliant!

Thanks for the help!