From f80bc08b81ecf72b751a18feceb1d39f48e06c0e Mon Sep 17 00:00:00 2001 From: Noreu Date: Sat, 19 Oct 2024 19:30:26 +0200 Subject: [PATCH] Add FastAPI example (#96) --- docs/content/guide/index.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/content/guide/index.md b/docs/content/guide/index.md index 0c092ea..bf0ce62 100644 --- a/docs/content/guide/index.md +++ b/docs/content/guide/index.md @@ -193,4 +193,20 @@ def environment(loader: FileSystemLoader, **options): #### FastAPI: -TBD \ No newline at end of file +```python +import jinjax +from fastapi import FastAPI, Request +from fastapi.templating import Jinja2Templates + +app = FastAPI() + +templates = Jinja2Templates(directory="templates") + +templates.env.add_extension(jinjax.JinjaX) +catalog = jinjax.Catalog(jinja_env=templates.env) +catalog.add_folder("templates/components") + +@app.get("/") +def get_index(request: Request): + return templates.TemplateResponse("index.html", {"request": request}) +```