Readme, corrected docstrings, tokens in .env_debug
This commit is contained in:
parent
6b9d616808
commit
a85619a9fb
4 changed files with 265 additions and 10 deletions
|
@ -13,8 +13,10 @@ async def get_form(
|
|||
form: Type[T],
|
||||
req: Request) -> T:
|
||||
"""Almost the same as `form.from_formdata`,
|
||||
and must be used *instead* of instantiatng
|
||||
form object directly as in Flask
|
||||
and must be used *instead* of instantiating
|
||||
form object directly as in Flask.
|
||||
See `respond.with_tmpl` for explanation
|
||||
about the `request` argument
|
||||
|
||||
Args:
|
||||
form (Type[StarletteForm]): StarletteForm class
|
||||
|
|
|
@ -70,16 +70,32 @@ def with_tmpl(
|
|||
background: Optional[BackgroundTask] = None,
|
||||
**context) -> Response:
|
||||
"""Render a Jinja2 template and return Response object.
|
||||
`response_class` parameter is not needed
|
||||
`response_class` parameter is not needed.
|
||||
A small explanation about the `request` function argument:
|
||||
```python
|
||||
from fastapi import Request
|
||||
from . import respond
|
||||
|
||||
@app.get('/')
|
||||
async def main_page(req: Request): # <--
|
||||
return respond.with_tmpl(
|
||||
'index.html',
|
||||
request=req, # <--
|
||||
...
|
||||
)
|
||||
```
|
||||
FastAPI will automatically pass the Request object
|
||||
to your function if you specify
|
||||
the correct type hint (`: Request`)
|
||||
|
||||
Args:
|
||||
name (str): Template filename
|
||||
request (Request): FastAPI request object
|
||||
code (int, optional): HTTP response code
|
||||
headers (Optional[Mapping[str, str]], optional):
|
||||
Additional headers, passed to Response constructor
|
||||
Additional headers, passed to the Response constructor
|
||||
background (Optional[BackgroundTask], optional):
|
||||
Background task, passed to Response constructor
|
||||
Background task, passed to the Response constructor
|
||||
|
||||
Returns:
|
||||
FastAPI's TemplateResponse object
|
||||
|
@ -102,8 +118,8 @@ def with_file(
|
|||
mime: Optional[str] = None,
|
||||
code: int = 200,
|
||||
*args, **kwargs) -> FileResponse:
|
||||
"""Send a file specified in `path`
|
||||
automatically guessing mimetype if `mime` is None.
|
||||
"""Send the file specified in `path`
|
||||
automatically guessing its mimetype if `mime` is None.
|
||||
`args` and `kwargs` are passed directly
|
||||
to the Response contructor
|
||||
|
||||
|
@ -113,7 +129,7 @@ def with_file(
|
|||
code (int, optional): HTTP response code
|
||||
|
||||
Returns:
|
||||
FileResponse: FastAPI's FileResponse object
|
||||
FastAPI's FileResponse object
|
||||
"""
|
||||
|
||||
return FileResponse(
|
||||
|
|
Loading…
Add table
Reference in a new issue