tmpl-fastapi/app/forms/__init__.py

30 lines
713 B
Python
Raw Normal View History

"""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
"""
2023-02-27 19:05:57 +04:00
return await form.from_formdata(request=req)