API Layout¶
-
class
layout.
BaseInput
(name, value, **kwargs)[source]¶ A base class to reduce the amount of code in the Input classes.
-
class
layout.
Button
(*args, **kwargs)[source]¶ Used to create a Submit input descriptor for the {% crispy %} template tag:
button = Button('Button 1', 'Press Me!')
Note
The first argument is also slugified and turned into the id for the button.
-
class
layout.
ButtonHolder
(*fields, **kwargs)[source]¶ Layout object. It wraps fields in a <div class=”buttonHolder”>
This is where you should put Layout objects that render to form buttons like Submit. It should only hold HTML and BaseInput inherited objects.
Example:
ButtonHolder( HTML(<span style="display: hidden;">Information Saved</span>), Submit('Save', 'Save') )
-
class
layout.
Column
(*fields, **kwargs)[source]¶ Layout object. It wraps fields in a div so the wrapper can be used as a column. Example:
Column('form_field_1', 'form_field_2')
- Depending on the template, css class associated to the div is formColumn, row, or nothing. For this last case, you
must provide css classes. Example:
Column('form_field_1', 'form_field_2', css_class='col-xs-6',)
-
class
layout.
Div
(*fields, **kwargs)[source]¶ Layout object. It wraps fields in a <div>
You can set css_id for a DOM id and css_class for a DOM class. Example:
Div('form_field_1', 'form_field_2', css_id='div-example', css_class='divs')
-
class
layout.
Field
(*args, **kwargs)[source]¶ Layout object, It contains one field name, and you can add attributes to it easily. For setting class attributes, you need to use css_class, as class is a Python keyword.
Example:
Field('field_name', style="color: #333;", css_class="whatever", id="field_name")
-
class
layout.
Fieldset
(legend, *fields, **kwargs)[source]¶ Layout object. It wraps fields in a <fieldset>
Example:
Fieldset("Text for the legend", 'form_field_1', 'form_field_2' )
The first parameter is the text for the fieldset legend. This text is context aware, so you can do things like:
Fieldset("Data for {{ user.username }}", 'form_field_1', 'form_field_2' )
-
class
layout.
HTML
(html)[source]¶ Layout object. It can contain pure HTML and it has access to the whole context of the page where the form is being rendered.
Examples:
HTML("{% if saved %}Data saved{% endif %}") HTML('<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />')
-
class
layout.
Hidden
(name, value, **kwargs)[source]¶ Used to create a Hidden input descriptor for the {% crispy %} template tag.
-
class
layout.
Layout
(*fields)[source]¶ Form Layout. It is conformed by Layout objects: Fieldset, Row, Column, MultiField, HTML, ButtonHolder, Button, Hidden, Reset, Submit and fields. Form fields have to be strings. Layout objects Fieldset, Row, Column, MultiField and ButtonHolder can hold other Layout objects within. Though ButtonHolder should only hold HTML and BaseInput inherited classes: Button, Hidden, Reset and Submit.
Example:
helper.layout = Layout( Fieldset('Company data', 'is_company' ), Fieldset(_('Contact details'), 'email', Row('password1', 'password2'), 'first_name', 'last_name', HTML('<img src="/media/somepicture.jpg"/>'), 'company' ), ButtonHolder( Submit('Save', 'Save', css_class='button white'), ), )
-
class
layout.
MultiField
(label, *fields, **kwargs)[source]¶ MultiField container. Renders to a MultiField <div>
-
class
layout.
MultiWidgetField
(*args, **kwargs)[source]¶ Layout object. For fields with
MultiWidget
as widget, you can pass additional attributes to each widget.Example:
MultiWidgetField( 'multiwidget_field_name', attrs=( {'style': 'width: 30px;'}, {'class': 'second_widget_class'} ), )
Note
To override widget’s css class use
class
notcss_class
.
-
class
layout.
Reset
(*args, **kwargs)[source]¶ Used to create a Reset button input descriptor for the {% crispy %} template tag:
reset = Reset('Reset This Form', 'Revert Me!')
Note
The first argument is also slugified and turned into the id for the reset.