Skip to content

Instantly share code, notes, and snippets.

@intellectronica
Last active September 25, 2024 10:06
Show Gist options
  • Save intellectronica/e887914d5015da94e00926691d29453e to your computer and use it in GitHub Desktop.
Save intellectronica/e887914d5015da94e00926691d29453e to your computer and use it in GitHub Desktop.
from fasthtml.common import *
app, rt = fast_app()
@app.get("/showtime")
def showtime():
return Script("document.getElementById('time').innerText = (new Date()).toLocaleTimeString();" id='showtimescript')
@app.get("/")
def home():
return (
Div(id='time'),
Script(id='showtimescript'),
Button('Show Time', hx_get='/showtime', hx_swap='outerHTML', hx_target='#showtimescript'),
)
serve()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment