1

I want to display the current time on a webpage with Flask. At the moment I have this code which displays the current time but does not update unless the user explicitly refresh the page.

<div id="datetime">
    <h2>{{ moment().format('HH:mm', refresh=True)}}</h2>
    <h2>{{ moment().format('ddd DD/MM/YY', refresh=True) }}</h2>
</div>

I am aware that the refresh option only re-renders the time and does not update it. How can I make it that the time stays up-to-date?

Ozzy Walsh
  • 877
  • 9
  • 17
  • 1
    You'll need to write JavaScript to update that string every second or so. – tyteen4a03 May 20 '17 at 19:57
  • Do you want the **server** time or the **client** (browser) time? – Laurent LAPORTE May 20 '17 at 19:57
  • @LaurentLAPORTE Actually, either could work. This is going to run on a Raspberry Pi. The Pi will run a flask app and display it on a monitor(as a sort of kiosk). So essentially client and server are the same. – Ozzy Walsh May 20 '17 at 20:01

1 Answers1

0

The best way to write this would be going the JavaScript route as @tyteen4a03 said. Take a look at this question for help: How do you show the current time on a web page?

Like you mentioned in the question, the only Flask/moment way to achieve something similar is using the Auto-refresh option.

Community
  • 1
  • 1
Jeremy
  • 1,894
  • 2
  • 13
  • 22