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=None,
*,
context_processors=None,
env=None,
**env_options
)
templates = Jinja2Templates("templates")
return templates.TemplateResponse("index.html", {"request": request})
PARAMETER | DESCRIPTION |
---|---|
directory |
TYPE:
|
context_processors |
TYPE:
|
env |
TYPE:
|
**env_options |
TYPE:
|
Source code in starlette/templating.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_template
¶
get_template(name)
PARAMETER | DESCRIPTION |
---|---|
name |
TYPE:
|
Source code in starlette/templating.py
136 137 |
|
TemplateResponse
¶
TemplateResponse(
request: Request,
name: str,
context: Optional[Dict[str, Any]] = None,
status_code: int = 200,
headers: Optional[Mapping[str, str]] = None,
media_type: Optional[str] = None,
background: Optional[BackgroundTask] = None,
) -> _TemplateResponse
TemplateResponse(
name: str,
context: Optional[Dict[str, Any]] = None,
status_code: int = 200,
headers: Optional[Mapping[str, str]] = None,
media_type: Optional[str] = None,
background: Optional[BackgroundTask] = None,
) -> _TemplateResponse
TemplateResponse(*args, **kwargs)
PARAMETER | DESCRIPTION |
---|---|
*args |
TYPE:
|
**kwargs |
TYPE:
|
Source code in starlette/templating.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|