WTForms support

The bootstrap/wtf.html template contains macros to help you output forms quickly. Flask-WTF is not a dependency of Flask-Bootstrap, however, and must be installed explicitly. The API of Flask-WTF has changed quite a bit over the last few versions, Flask-Bootstrap is currently developed for Flask-WTF version 0.9.2.

The most basic way is using them as an aid to create a form by hand:

<form class="form form-horizontal" method="post" role="form">
  {{ form.hidden_tag() }}
  {{ wtf.form_errors(form, hiddens="only") }}

  {{ wtf.form_field(form.field1) }}
  {{ wtf.form_field(form.field2) }}
</form>

However, often you just want to get a form done quickly and have no need for intense fine-tuning:

{{ wtf.quick_form(form) }}

Form macro reference

quick_form(form, action=".", method="post", extra_classes=None, role="form", form_type="basic", horizontal_columns=('lg', 2, 10), enctype=None, button_map={}, id="")

Outputs Bootstrap-markup for a complete Flask-WTF form.

Parameters:
  • form – The form to output.
  • method<form> method attribute.
  • extra_classes – The classes to add to the <form>.
  • role<form> role attribute.
  • form_type – One of basic, inline or horizontal. See the Bootstrap docs for details on different form layouts.
  • horizontal_columns – When using the horizontal layout, layout forms like this. Must be a 3-tuple of (column-type, left-column-size, right-colum-size).
  • enctype<form> enctype attribute. If None, will automatically be set to multipart/form-data if a FileField is present in the form.
  • button_map – A dictionary, mapping button field names to names such as primary, danger or success. Buttons not found in the button_map will use the default type of button.
  • id – The <form> id attribute.
form_errors(form, hiddens=True)

Renders paragraphs containing form error messages. This is usually only used to output hidden field form errors, as others are attached to the form fields.

Parameters:
  • form – Form, who’s errors should be rendered.
  • hiddens – If True, render errors of hidden fields as well. If 'only', render only these.
form_field(field, form_type="basic", horizontal_columns=('lg', 2, 10), button_map={})

Renders a single form-field with surrounding elements. Used mainly by quick_form.