From 5ae2146c4de58d4b6fa0cc181994538a953b30ee Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Mon, 3 Jun 2024 16:55:41 +0200 Subject: [PATCH] Update templates.md --- docs/en/docs/advanced/templates.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/en/docs/advanced/templates.md b/docs/en/docs/advanced/templates.md index 4a577215a9..7be37c6868 100644 --- a/docs/en/docs/advanced/templates.md +++ b/docs/en/docs/advanced/templates.md @@ -114,6 +114,15 @@ In this example, it would link to a CSS file at `static/styles.css` with: And because you are using `StaticFiles`, that CSS file would be served automatically by your **FastAPI** application at the URL `/static/styles.css`. +## Generating raw HTML from templates + +If you need to render HTML from a template, you can do so. + +```python +context = {"id": 1} +html = templates.get_template("item.html").render(context) +``` + ## More details For more details, including how to test templates, check Starlette's docs on templates.