Debian Codegraph @

docs/examples/onboarding/flask/static_files.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 ASSETS_DIR = Path(__file__).parent / "assets"
7
8
9 def ensure_assets() -> None:
10 ASSETS_DIR.mkdir(exist_ok=True)
11 ASSETS_DIR.joinpath("hello.txt").write_text("Hello, world!")
12
13
14 app = Litestar(
15 route_handlers=[
16 create_static_files_router(path="/static", directories=[ASSETS_DIR]),
17 ],
18 on_startup=[ensure_assets],
19 )