| 1 |
from pathlib import Path |
| 2 |
|
| 3 |
from litestar import Litestar, get |
| 4 |
from litestar.params import FromPath |
| 5 |
from litestar.plugins.jinja import JinjaTemplateEngine |
| 6 |
from litestar.response import Template |
| 7 |
from litestar.template.config import TemplateConfig |
| 8 |
|
| 9 |
|
| 10 |
@get("/hello/{name:str}", sync_to_thread=False) |
| 11 |
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 |
) |