tmpl-fastapi/app/forms/__init__.py

29 lines
713 B
Python

"""Module containing WTForms classes
and helper functions for Starlette-WTF"""
from typing import Type, TypeVar
from fastapi import Request
from starlette_wtf import StarletteForm
T = TypeVar('T', bound=StarletteForm)
async def get_form(
form: Type[T],
req: Request) -> T:
"""Almost the same as `form.from_formdata`,
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
req (Request): Request object
Returns:
StarletteForm instance
"""
return await form.from_formdata(request=req)