API templatetags

class templatetags.crispy_forms_tags.BasicNode(form, helper, template_pack=None)[source]

Basic Node object that we can rely on for Node objects in normal template tags. I created this because most of the tags we’ll be using will need both the form object and the helper string. This handles both the form object and parses out the helper string into attributes that templates can easily handle.

get_render(context)[source]

Returns a Context object with all the necessary stuff for rendering the form

Parameters

contextdjango.template.Context variable holding the context for the node

self.form and self.helper are resolved into real Python objects resolving them from the context. The actual_form can be a form or a formset. If it’s a formset is_formset is set to True. If the helper has a layout we use it, for rendering the form or the formset’s forms.

get_response_dict(helper, context, is_formset)[source]

Returns a dictionary with all the parameters necessary to render the form/formset in a template.

Parameters
  • contextdjango.template.Context for the node

  • is_formset – Boolean value. If set to True, indicates we are working with a formset.

class templatetags.crispy_forms_tags.CrispyFormNode(form, helper, template_pack=None)[source]
render(context)[source]

Return the node rendered as a string.

class templatetags.crispy_forms_tags.ForLoopSimulator(formset)[source]

Simulates a forloop tag, precisely:

{% for form in formset.forms %}

If {% crispy %} is rendering a formset with a helper, We inject a ForLoopSimulator object in the context as forloop so that formset forms can do things like:

Fieldset("Item {{ forloop.counter }}", [...])
HTML("{% if forloop.first %}First form text{% endif %}"
iterate()[source]

Updates values as if we had iterated over the for

templatetags.crispy_forms_tags.do_uni_form(parser, token)[source]

You need to pass in at least the form/formset object, and can also pass in the optional crispy_forms.helpers.FormHelper object.

helper (optional): A crispy_forms.helper.FormHelper object.

Usage:

{% load crispy_tags %}
{% crispy form form.helper %}

You can also provide the template pack as the third argument:

{% crispy form form.helper 'bootstrap' %}

If the FormHelper attribute is named helper you can simply do:

{% crispy form %}
{% crispy form 'bootstrap' %}
templatetags.crispy_forms_tags.whole_uni_form_template(template_pack=<SimpleLazyObject: 'bootstrap'>)[source]
templatetags.crispy_forms_tags.whole_uni_formset_template(template_pack=<SimpleLazyObject: 'bootstrap'>)[source]
templatetags.crispy_forms_filters.as_crispy_errors(form, template_pack=<SimpleLazyObject: 'bootstrap'>)[source]

Renders only form errors the same way as django-crispy-forms:

{% load crispy_forms_tags %}
{{ form|as_crispy_errors }}

or:

{{ form|as_crispy_errors:"bootstrap" }}
templatetags.crispy_forms_filters.as_crispy_field(field, template_pack=<SimpleLazyObject: 'bootstrap'>, label_class='', field_class='')[source]

Renders a form field like a django-crispy-forms field:

{% load crispy_forms_tags %}
{{ form.field|as_crispy_field }}

or:

{{ form.field|as_crispy_field:"bootstrap" }}
templatetags.crispy_forms_filters.as_crispy_form(form, template_pack=<SimpleLazyObject: 'bootstrap'>, label_class='', field_class='')[source]

The original and still very useful way to generate a div elegant form/formset:

{% load crispy_forms_tags %}

<form class="uniForm" method="post">
    {% csrf_token %}
    {{ myform|crispy }}
</form>

or, if you want to explicitly set the template pack:

{{ myform|crispy:"bootstrap" }}

In bootstrap3 or bootstrap4 for horizontal forms you can do:

{{ myform|label_class:"col-lg-2",field_class:"col-lg-8" }}
templatetags.crispy_forms_filters.flatatt_filter(attrs)[source]
templatetags.crispy_forms_filters.optgroups(field)[source]

A template filter to help rendering of fields with optgroups.

Returns a tuple of label, option, index:

label: Group label for grouped optgroups (`None` if inputs are not
       grouped).
option: A dict containing information to render the option:
    {
        "name": "checkbox_select_multiple",
        "value": 1,
        "label": 1,
        "selected": False,
        "index": "0",
        "attrs": {"id": "id_checkbox_select_multiple_0"},
        "type": "checkbox",
        "template_name": "django/forms/widgets/checkbox_option.html",
        "wrap_label": True,
    }
index: Group index
templatetags.crispy_forms_filters.uni_form_template(template_pack=<SimpleLazyObject: 'bootstrap'>)[source]
templatetags.crispy_forms_filters.uni_formset_template(template_pack=<SimpleLazyObject: 'bootstrap'>)[source]
class templatetags.crispy_forms_field.CrispyFieldNode(field, attrs)[source]
render(context)[source]

Return the node rendered as a string.

templatetags.crispy_forms_field.classes(field)[source]

Returns CSS classes of a field

templatetags.crispy_forms_field.crispy_addon(field, append='', prepend='', form_show_labels=True)[source]

Renders a form field using bootstrap’s prepended or appended text:

{% crispy_addon form.my_field prepend="$" append=".00" %}

You can also just prepend or append like so

{% crispy_addon form.my_field prepend=”$” %} {% crispy_addon form.my_field append=”.00” %}

templatetags.crispy_forms_field.crispy_field(parser, token)[source]

{% crispy_field field attrs %}

templatetags.crispy_forms_field.css_class(field)[source]

Returns widgets class name in lowercase

templatetags.crispy_forms_field.is_checkbox(field)[source]
templatetags.crispy_forms_field.is_checkboxselectmultiple(field)[source]
templatetags.crispy_forms_field.is_clearable_file(field)[source]
templatetags.crispy_forms_field.is_file(field)[source]
templatetags.crispy_forms_field.is_multivalue(field)[source]
templatetags.crispy_forms_field.is_password(field)[source]
templatetags.crispy_forms_field.is_radioselect(field)[source]
templatetags.crispy_forms_field.is_select(field)[source]
templatetags.crispy_forms_field.pairwise(iterable)[source]

s -> (s0,s1), (s2,s3), (s4, s5), …