Debian Codegraph @

docs/examples/static_files/html_mode.py

raw
1 from pathlib import Path
2
3 from litestar import Litestar
4 from litestar.static_files import create_static_files_router
5
6 HTML_DIR = Path("html")
7
8
9 def on_startup() -> None:
10 HTML_DIR.mkdir(exist_ok=True)
11 HTML_DIR.joinpath("index.html").write_text("<strong>Hello, world!</strong>")
12 HTML_DIR.joinpath("404.html").write_text("<h1>Not found</h1>")
13
14
15 app = Litestar(
16 route_handlers=[
17 create_static_files_router(
18 path="/",
19 directories=["html"],
20 html_mode=True,
21 )
22 ],
23 on_startup=[on_startup],
24 )
25
26
27 # run: /
28 # run: /index.html
29 # run: /something