Form
This class represents form data submitted with the "application/x-www-form-urlencoded" media type. It extends the Body class to handle form-specific parameters and validation rules, allowing for detailed specification of form fields, including length constraints, patterns, and examples. It supports defining default values, aliases, and schema generation properties for robust form data handling.
Constructor
Signature
def Form(
default: Any = Undefined,
default_factory: Callable[[], Any]| None = _Unset,
annotation: Any | None = None,
media_type: str = "application/x-www-form-urlencoded",
alias: str | None = None,
alias_priority: int | None = _Unset,
validation_alias: str | AliasPath | AliasChoices | None = None,
serialization_alias: str | None = None,
title: str | None = None,
description: str | None = None,
gt: float | None = None,
ge: float | None = None,
lt: float | None = None,
le: float | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | None = None,
regex: Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.")] = None,
discriminator: str | None = None,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any]| None = None,
example: Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")] = _Unset,
openapi_examples: dict[str, [Example](../openapi/models/example.md?sid=fastapi_openapi_models_example)]| None = None,
deprecated: deprecated | str | bool | None = None,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any]| None = None,
extra: Any = None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| default | Any = Undefined | The default value for the form field. |
| default_factory | `Callable[[], Any] | None` = _Unset |
| annotation | `Any | None` = None |
| media_type | str = "application/x-www-form-urlencoded" | The media type of the form data. |
| alias | `str | None` = None |
| alias_priority | `int | None` = _Unset |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` = None |
| title | `str | None` = None |
| description | `str | None` = None |
| gt | `float | None` = None |
| ge | `float | None` = None |
| lt | `float | None` = None |
| le | `float | None` = None |
| min_length | `int | None` = None |
| max_length | `int | None` = None |
| pattern | `str | None` = None |
| regex | `Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use pattern instead.")]` = None |
| discriminator | `str | None` = None |
| strict | `bool | None` = _Unset |
| multiple_of | `float | None` = _Unset |
| allow_inf_nan | `bool | None` = _Unset |
| max_digits | `int | None` = _Unset |
| decimal_places | `int | None` = _Unset |
| examples | `list[Any] | None` = None |
| example | `Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")]` = _Unset |
| openapi_examples | `dict[str, Example] | None` = None |
| deprecated | `deprecated | str |
| include_in_schema | bool = True | Whether to include the form field in the OpenAPI schema. |
| json_schema_extra | `dict[str, Any] | None` = None |
| extra | Any = None | Additional keyword arguments. |
Signature
def Form(
default: Any = Undefined,
default_factory: Callable[[], Any]| None = _Unset,
annotation: Any | None = null,
media_type: str = "application/x-www-form-urlencoded",
alias: str | None = null,
alias_priority: int | None = _Unset,
validation_alias: str | AliasPath | AliasChoices | None = null,
serialization_alias: str | None = null,
title: str | None = null,
description: str | None = null,
gt: float | None = null,
ge: float | None = null,
lt: float | None = null,
le: float | None = null,
min_length: int | None = null,
max_length: int | None = null,
pattern: str | None = null,
regex: Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.")] = null,
discriminator: str | None = null,
strict: bool | None = _Unset,
multiple_of: float | None = _Unset,
allow_inf_nan: bool | None = _Unset,
max_digits: int | None = _Unset,
decimal_places: int | None = _Unset,
examples: list[Any]| None = null,
example: Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")] = _Unset,
openapi_examples: dict[str, [Example](../openapi/models/example.md?sid=fastapi_openapi_models_example)]| None = null,
deprecated: deprecated | str | bool | None = null,
include_in_schema: bool = True,
json_schema_extra: dict[str, Any]| None = null,
extra: Any = null
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| default | Any = Undefined | The default value for the form field if no value is provided. Use Undefined to indicate no default. |
| default_factory | `Callable[[], Any] | None` = _Unset |
| annotation | `Any | None` = null |
| media_type | str = "application/x-www-form-urlencoded" | The media type of the form data. Defaults to 'application/x-www-form-urlencoded' for standard HTML forms. |
| alias | `str | None` = null |
| alias_priority | `int | None` = _Unset |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` = null |
| title | `str | None` = null |
| description | `str | None` = null |
| gt | `float | None` = null |
| ge | `float | None` = null |
| lt | `float | None` = null |
| le | `float | None` = null |
| min_length | `int | None` = null |
| max_length | `int | None` = null |
| pattern | `str | None` = null |
| regex | `Annotated[str | None, deprecated("Deprecated in FastAPI 0.100.0 and Pydantic v2, use pattern instead.")]` = null |
| discriminator | `str | None` = null |
| strict | `bool | None` = _Unset |
| multiple_of | `float | None` = _Unset |
| allow_inf_nan | `bool | None` = _Unset |
| max_digits | `int | None` = _Unset |
| decimal_places | `int | None` = _Unset |
| examples | `list[Any] | None` = null |
| example | `Annotated[Any | None, deprecated("Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, although still supported. Use examples instead.")]` = _Unset |
| openapi_examples | `dict[str, Example] | None` = null |
| deprecated | `deprecated | str |
| include_in_schema | bool = True | If set to False, the form field will not be included in the generated OpenAPI schema. |
| json_schema_extra | `dict[str, Any] | None` = null |
| extra | Any = null | Additional keyword arguments that will be passed to the parent Body class. |