EmailField
class
EmailField
A field for normalizing and validating email addresses.
This field requires the
email_validator
Python library to be installed.
EmailField(
*,
required: bool = True,
default: Any = None,
check_dns: bool = False,
allow_smtputf8: bool = False,
strict: bool = True,
one_of: collections.abc.Iterable[str] | None = None,
messages: dict[str, str] | None = None
)
Bases: Field
| Argument | Description |
|---|---|
required |
Whether the field is required. Defaults to |
default |
Default value for the field. Can be a static value or a callable.
Defaults to |
check_dns |
If |
allow_smtputf8 |
Accept non-ASCII characters in the local part of the address
(before the @-sign). These email addresses require that your mail
submission library and the mail servers along the route to the destination,
including your own outbound mail server, all support the
SMTPUTF8 extension (RFC 6531, https://tools.ietf.org/html/rfc6531).
By default this is set to |
strict |
if |
one_of |
List of values that the field value must be one of. Defaults to |
messages |
Dictionary of error codes to custom error message templates. These override the default error messages for this specific field. Example: {"required": "This field cannot be empty"}. |
It uses the email_validator library for normalization, which includes:
- Lowercasing the domain part of the email address, because domain names are case-insensitive.
- Unicode "NFC" normalization of the whole address, which turns characters plus combining characters into precomposed characters where possible and replaces certain Unicode characters (such as angstrom and ohm) with other equivalent code points (a-with-ring and omega), replacement of fullwidth and halfwidth characters in the domain part, and possibly other UTS46 mappings on the domain part.