Create a templates object that you can reuse later.
Declare a Request parameter in the path operation that will return a template.
Use the templates you created to render and return a TemplateResponse, pass the name of the template, the request object, and a "context" dictionary with key-value pairs to be used inside of the Jinja2 template.
Before FastAPI 0.108.0, Starlette 0.29.0, the name was the first parameter.
Also, before that, in previous versions, the request object was passed as part of the key-value pairs in the context for Jinja2.
Tip
By declaring response_class=HTMLResponse the docs UI will be able to know that the response will be HTML.
Technical Details
You could also use from starlette.templating import Jinja2Templates.
FastAPI provides the same starlette.templating as fastapi.templating just as a convenience for you, the developer. But most of the available responses come directly from Starlette. The same with Request and StaticFiles.