BooleanField

class BooleanField

A field that represents a boolean value.

BooleanField(
    *,
    required: bool = False,
    default: Any = None,
    messages: dict[str, str] | None = None
)

Bases: Field

ArgumentDescription
required

Whether the field value must be True. Defaults to False.

default

Default value for the field. Can be a static value or a callable. Defaults to None.

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"}.

Boolean fields are treated specially because of how browsers handle checkboxes:

  • If not checked: the browser doesn't send the field at all.
  • If checked: It sends the "value" attribute, but this is optional, so it could send an empty string instead.

For these reasons:

  • A missing field (a None value) will become False.
  • A string value in the FALSE_VALUES tuple (case-insensitive) will become False.
  • Any other value, including an empty string, will become True.