Form & Fields#

Form#

class quart_wtf.QuartForm(*args, **kwargs)#

Quart specific subclass of WTForms Form. To populate from submitted formdata use the `.create_form` class method to initialize the instance.

Parameters:
  • formdata – Input data coming from the client, usually

  • "multi (request.form or equivalent. Should provide a)

  • key. (dict" interface to get a list of values for a given)

  • obj – Take existing data from attributes on this object

  • is (matching form field attributes. Only used if formdata)

  • passed. (not)

  • prefix – If provided, all fields will have their name

  • multiple (prefixed with the value. This is for distinguishing)

  • for (forms on a single page. This only affects the HTML name)

  • data (matching input)

  • matching (not the Python name for)

  • data. (existing)

  • data – Take existing data from keys in this dict matching

  • also (form field attributes. obj takes precedence if it)

  • not (has a matching attribute. Only used if formdata is)

  • passed.

  • meta – A dict of attributes to override on this form’s

:param meta instance.: :param extra_filters: A dict mapping field attribute names to :param lists of extra filter functions to run. Extra filters run: :param after filters passed when creating the field. If the form: :param has filter_<fieldname>: :param it is the last extra filter.: :param kwargs: Merged with data to allow passing existing :param data as parameters. Overwrites any duplicate keys in: :param data. Only used if formdata is not passed.:

Meta#

alias of QuartFormMeta

async classmethod create_form(formdata: object | CombinedMultiDict | ImmutableDict | MultiDict = _Auto, obj: Any | None = None, prefix: str = '', data: Dict | None = None, meta: Dict | None = None, **kwargs: Dict[str, Any]) QuartForm#

This creates a new instance of the form and can only be called within your applications routes.

This method is primiarly used to intialize the class from submitted formdata from Quart.request. If a request is a POST, PUT, PATCH, or DELETE method. The form will be intialized using the request. Otherwise it will initialized using the defaults. This is required since request.files, request.form, and request.json are coroutines and need to be called in an async manner.

Parameters:
  • formdata – Input data coming from the client, usually

  • "multi (request.form or equivalent. Should provide a)

  • key. (dict" interface to get a list of values for a given)

  • obj – Take existing data from attributes on this object

  • is (matching form field attributes. Only used if formdata)

  • passed. (not)

  • prefix – If provided, all fields will have their name

  • multiple (prefixed with the value. This is for distinguishing)

  • for (forms on a single page. This only affects the HTML name)

  • data (matching input)

  • matching (not the Python name for)

  • data. (existing)

  • data – Take existing data from keys in this dict matching

  • also (form field attributes. obj takes precedence if it)

  • not (has a matching attribute. Only used if formdata is)

  • passed.

  • meta – A dict of attributes to override on this form’s

:param meta instance.: :param extra_filters: A dict mapping field attribute names to :param lists of extra filter functions to run. Extra filters run: :param after filters passed when creating the field. If the form: :param has filter_<fieldname>: :param it is the last extra filter.: :param kwargs: Merged with data to allow passing existing :param data as parameters. Overwrites any duplicate keys in: :param data. Only used if formdata is not passed.:

async validate(extra_validators: Dict[str, Any] | None = None) bool#

Async Overload validate() to handle custom async validators.

Parameters:

extra_validators – Extra form validators.

property is_submitted: bool#

Consider the form submitted if there is an active request and the method is POST, PUT, PATCH, or DELETE.

async validate_on_submit(extra_validators: Dict[str, Any] | None = None) bool#

Call validate() only if the form is submitted. This is a shortcut for QuartForm.is_submitted and ``QuartForm.validate().

Parameters:

extra_validators – Extra form validators.

hidden_tag(*fields) Markup#

Render the form’s hidden fields in one call. A field is considered hidden if it uses the HiddenInput widget. If fields are given, only render the given fields that are hidden. If a string is passed, render the field with that name if it exists.

Argument:

fields: Form fields.

class quart_wtf.meta.QuartFormMeta#

Quart specific meta class for WTForms.

property csrf: bool#

CSRF Enabled.

property csrf_secret: Any#

CSRF secret key.

property csrf_field_name: str#

CSRF field name.

property csrf_time_limit: int#

CSRF time limit.

get_translations(form)#

Gets translations for the form. If the configuration variable ‘WTF_I18N_ENABLED’ is False will use DefaultMeta.get_translations.

Fields#

class quart_wtf.FileField(*args, **kwargs)#

Werkzeug-aware subclass of wtforms.fields.FileField.

class quart_wtf.FileAllowed(upload_set: UploadSet, message: str | None = None)#

Validates that the uploaded file is allowed by a given list of extensions or a Quart-Uploads UploadSet.

You can also use the synonym file_allowed.

Argument:

upload_set: A list of extensions or an UploadSet

class quart_wtf.FileRequired(message=None)#

Validates that the data is a FileStorage object.

You can also use the synonym file_required.

Argument:

message (str): Error message.