Skip to content

Commit

Permalink
Add FastAPI example (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noreu authored Oct 19, 2024
1 parent 99f0072 commit f80bc08
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/content/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,20 @@ def environment(loader: FileSystemLoader, **options):

#### FastAPI:

TBD
```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})
```

0 comments on commit f80bc08

Please sign in to comment.