Templating - Jinja2Templates
¶
You can use the Jinja2Templates
class to render Jinja templates.
Read more about it in the FastAPI docs for Templates.
You can import it directly from fastapi.templating
:
from fastapi.templating import Jinja2Templates
fastapi.templating.Jinja2Templates ¶
Jinja2Templates(
directory, context_processors=None, **env_options
)
templates = Jinja2Templates("templates")
return templates.TemplateResponse("index.html", {"request": request})
PARAMETER | DESCRIPTION |
---|---|
directory |
TYPE:
|
context_processors |
TYPE:
|
**env_options |
TYPE:
|
Source code in starlette/templating.py
65 66 67 68 69 70 71 72 73 74 75 |
|
get_template ¶
get_template(name)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
Source code in starlette/templating.py
93 94 |
|
TemplateResponse ¶
TemplateResponse(
name,
context,
status_code=200,
headers=None,
media_type=None,
background=None,
)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
context |
TYPE:
|
status_code |
TYPE:
|
headers |
TYPE:
|
media_type |
TYPE:
|
background |
TYPE:
|
Source code in starlette/templating.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|