-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (37 loc) · 893 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from typing import Union
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/hello", response_class=HTMLResponse)
async def hello():
return """
<html>
<head>
<title>Hello...</title>
</head>
<body>
<div id="parent-div">
<h1>Hello...</h1>
</div>
<button
hx-get="/world"
hx-trigger="click"
hx-target="#parent-div"
hx-swap="innerHTML"
>Click Me!
</button>
<script src="/static/htmx.min.js"></script>
</body>
</html>
"""
@app.get("/world", response_class=HTMLResponse)
async def world():
return """
<title>...world</title>
<h1>...world</h1>
"""