API Bootstrap
- class crispy_forms.bootstrap.Accordion(*accordion_groups, css_id=None, css_class=None, template=None, **kwargs)[source]
Accordion menu object. It wraps AccordionGroup objects in a container
- Parameters:
- *accordion_groupsstr, LayoutObject
Any number of layout objects as positional arguments to be rendered within the
<div>
.- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default None.
Examples
Example:
Accordion( AccordionGroup("group name", "form_field_1", "form_field_2"), AccordionGroup("another group name", "form_field") )
- class crispy_forms.bootstrap.AccordionGroup(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)[source]
Accordion Group (pane) object. It wraps given fields inside an accordion tab. It takes accordion tab name as first argument.
Tab object. It wraps fields in a div whose default class is “tab-pane” and takes a name as first argument.
- Parameters:
- namestr
The name of the container.
- *fieldsstr, LayoutObject
Any number of fields as positional arguments to be rendered within the container.
- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default “”.
Examples
Example:
AccordionGroup("group name", "form_field_1", "form_field_2")
- class crispy_forms.bootstrap.Alert(content, dismiss=True, block=False, css_id=None, css_class=None, template=None, **kwargs)[source]
Generates markup in the form of an alert dialog.
- Parameters:
- contentstr
The content of the alert.
- dismissbool
If true the alert contains a button to dismiss the alert. By default True.
- blockstr, optional
Additional CSS classes to be applied to the
<button>
. By default None.- css_idstr, optional
A DOM id for the layout object which will be added to the alert if provided. By default None.
- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are then available in the template context.
- Attributes:
- template: str
The default template which this Layout Object will be rendered with.
- css_classstr
The CSS classes to be applied to the alert. By defult “alert”.
Examples
Example:
Alert(content='<strong>Warning!</strong> Best check yo self, you're not looking too good.')
- class crispy_forms.bootstrap.AppendedText(field, text, *, input_size=None, active=False, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering a field with appended text.
- Parameters:
- fieldstr
The name of the field to be rendered.
- textstr
The appended text, can be HTML like.
- input_sizestr, optional
For Bootstrap4+ additional classes to customise the input-group size e.g.
input-group-sm
. By default None- activebool
For Bootstrap3, a boolean to render the text active. By default
False
.- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
AppendedText('amount', '.00')
- class crispy_forms.bootstrap.Container(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)[source]
Base class used for Tab and AccordionGroup, represents a basic container concept.
- Parameters:
- namestr
The name of the container.
- *fieldsstr, LayoutObject
Any number of fields as positional arguments to be rendered within the container.
- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default “”.
- class crispy_forms.bootstrap.ContainerHolder(*fields, css_id=None, css_class=None, template=None, **kwargs)[source]
Base class used for TabHolder and Accordion, groups containers.
- Parameters:
- *fieldsstr, LayoutObject
Any number of fields or layout objects as positional arguments to be rendered within the
<div>
.- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default None.
- class crispy_forms.bootstrap.FieldWithButtons(*fields, input_size=None, css_id=None, css_class=None, template=None, **kwargs)[source]
A layout object for rendering a single field with any number of buttons.
- Parameters:
- *fieldsstr or LayoutObject
The first positional argument is the field. This can be either the name of the field as a string or an instance of Field. Following arguments will be rendered as buttons.
- input_sizestr
Additional CSS class to change the size of the input. e.g. “input-group-sm”.
- css_idstr, optional
A DOM id for the layout object which will be added to the wrapping
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the wrapping<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the wrapping
<div>
. By default None.
Examples
Example:
FieldWithButtons( Field("password1", css_class="span4"), StrictButton("Go!", css_id="go-button"), input_size="input-group-sm", )
- class crispy_forms.bootstrap.FormActions(*fields, css_id=None, css_class=None, template=None, **kwargs)[source]
Bootstrap layout object. It wraps fields in a <div class=”form-actions”>
- Parameters:
- *fieldsHTML or BaseInput
The layout objects to render within the
ButtonHolder
. It should only hold HTML and BaseInput inherited objects.- css_idstr, optional
A custom DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied to the
<div>
. By default None.- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- template: str
The default template which this Layout Object will be rendered with.
Examples
An example using
FormActions
in your layout:FormActions( HTML(<span style="display: hidden;">Information Saved</span>), Submit('Save', 'Save', css_class='btn-primary') )
- class crispy_forms.bootstrap.InlineCheckboxes(*fields, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering checkboxes inline.
- Parameters:
- *fieldsstr
Usually a single field, but can be any number of fields, to be rendered with the same attributes applied.
- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
InlineCheckboxes('field_name')
- class crispy_forms.bootstrap.InlineField(*fields, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering fields as Inline in bootstrap.
- Parameters:
- *fieldsstr
Usually a single field, but can be any number of fields, to be rendered with the same attributes applied.
- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
InlineField('field_name')
- class crispy_forms.bootstrap.InlineRadios(*fields, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering radiobuttons inline.
- Parameters:
- *fieldsstr
Usually a single field, but can be any number of fields, to be rendered with the same attributes applied.
- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
InlineRadios('field_name')
- class crispy_forms.bootstrap.Modal(*fields, template=None, css_id='modal_id', title='Modal Title', title_id='modal_title_id', css_class=None, title_class=None, **kwargs)[source]
Boostrap layout object for rendering crispy forms objects inside a bootstrap modal.
- Parameters:
- *fieldsstr
The fields to be rendered within the modal.
- templatestr, optional
Overrides the default template, if provided. By default
None
.- css_id: str, optional
The modal’s DOM id. By default
modal_id
.- title: str, optional
Text to display in the modal’s header which will be wrapped in an
<H5>
tag. By defaultModal Title
.- title_id: str, optional
The title’s DOM id. By default
modal_title_id
.- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By default None.- title_class: str, optional
Additional CSS classes to be applied to the title. By default None.
- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
Examples
Example:
Modal( 'field1', Div('field2'), css_id="modal-id-ex", css_class="modal-class-ex, title="This is my modal", )
- class crispy_forms.bootstrap.PrependedAppendedText(field, prepended_text=None, appended_text=None, input_size=None, *, active=False, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering a field with prepended and appended text.
- Parameters:
- fieldstr
The name of the field to be rendered.
- prepended_textstr, optional
The prepended text, can be HTML like, by default None
- appended_textstr, optional
The appended text, can be HTML like, by default None
- input_sizestr, optional
For Bootstrap4+ additional classes to customise the input-group size e.g.
input-group-sm
. By default None- activebool
For Bootstrap3, a boolean to render the text active. By default
False
.- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
PrependedAppendedText('amount', '$', '.00')
- class crispy_forms.bootstrap.PrependedText(field, text, *, input_size=None, active=False, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering a field with prepended text.
- Parameters:
- fieldstr
The name of the field to be rendered.
- textstr
The prepended text, can be HTML like.
- input_sizestr, optional
For Bootstrap4+ additional classes to customise the input-group size e.g.
input-group-sm
. By default None- activebool
For Bootstrap3, a boolean to render the text active. By default
False
.- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
PrependedText('amount', '$')
- class crispy_forms.bootstrap.StrictButton(content, css_id=None, css_class=None, template=None, **kwargs)[source]
Layout object for rendering an HTML button in a
<button>
tag.- Parameters:
- contentstr
The content of the button. This content is context aware, to bring this to life see the examples section.
- css_idstr, optional
A custom DOM id for the layout object which will be added to the
<button>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied to the
<button>
. By default None.- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to flatatt and converted into key=”value”, pairs. These attributes are added to the
<button>
.
- Attributes:
- template: str
The default template which this Layout Object will be rendered with.
- field_classesstr
The CSS classes to be applied to the button. By defult “btn”.
Examples
In your
Layout
:StrictButton("button content", css_class="extra")
The content of the button is context aware, so you can do things like:
StrictButton("Button for {{ user.username }}")
- class crispy_forms.bootstrap.Tab(name, *fields, css_id=None, css_class=None, template=None, active=None, **kwargs)[source]
Tab object. It wraps fields in a div whose default class is “tab-pane” and takes a name as first argument.
- Parameters:
- namestr
The name of the container.
- *fieldsstr, LayoutObject
Any number of fields as positional arguments to be rendered within the container.
- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default “”.
Examples
Example:
Tab('tab_name', 'form_field_1', 'form_field_2', 'form_field_3')
- class crispy_forms.bootstrap.TabHolder(*fields, css_id=None, css_class=None, template=None, **kwargs)[source]
TabHolder object. It wraps Tab objects in a container.
- Parameters:
- *fieldsstr, LayoutObject
Any number of fields or layout objects as positional arguments to be rendered within the
<div>
.- css_idstr, optional
A DOM id for the layout object which will be added to the
<div>
if provided. By default None.- css_classstr, optional
Additional CSS classes to be applied in addition to those declared by the class itself. By default None.
- templatestr, optional
Overrides the default template, if provided. By default None.
- **kwargsdict, optional
Additional attributes are passed to
flatatt
and converted into key=”value”, pairs. These attributes are added to the<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- css_classstr, optional
CSS classes to be applied to the
<div>
. By default None.
Examples
Example:
TabHolder( Tab('form_field_1', 'form_field_2'), Tab('form_field_3') )
- class crispy_forms.bootstrap.UneditableField(field, css_class=None, wrapper_class=None, template=None, **kwargs)[source]
Layout object for rendering fields as uneditable in bootstrap.
- Parameters:
- fieldsstr
The name of the field.
- css_classstr, optional
CSS classes to be applied to the field. These are added to any classes included in the
attrs
dict. By defaultNone
.- wrapper_class: str, optional
CSS classes to be used when rendering the Field. This class is usually applied to the
<div>
which wraps the Field’s<label>
and<input>
tags. By defaultNone
.- templatestr, optional
Overrides the default template, if provided. By default
None
.- **kwargsdict, optional
Additional attributes are converted into key=”value”, pairs. These attributes are added to the
<div>
.
- Attributes:
- templatestr
The default template which this Layout Object will be rendered with.
- attrsdict
Attributes to be applied to the field. These are converted into html attributes. e.g.
data_id: 'test'
in the attrs dict will becomedata-id='test'
on the field’s<input>
.
Examples
Example:
UneditableField('field_name', css_class="input-xlarge")