tmpl-fastapi/app/forms/__init__.py

28 lines
638 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 instantiatng
form object directly as in Flask
Args:
form (Type[StarletteForm]): StarletteForm class
req (Request): Request object
Returns:
StarletteForm instance
"""
return await form.from_formdata(request=req)