Debian Codegraph @

docs/examples/onboarding/django/templates.py

raw
1 from pathlib import Path
2
3 from litestar import Litestar, get
4 from litestar.contrib.jinja import JinjaTemplateEngine
5 from litestar.params import FromPath
6 from litestar.response import Template
7 from litestar.template.config import TemplateConfig
8
9
10 @get("/hello/{name:str}")
11 async def hello(name: FromPath[str]) -> Template:
12 return Template(
13 template_str="<p>Hello, {{ name }}!</p>",
14 context={"name": name},
15 )
16
17
18 app = Litestar(
19 route_handlers=[hello],
20 template_config=TemplateConfig(
21 directory=Path(__file__).parent,
22 engine=JinjaTemplateEngine,
23 ),
24 )