djangodocs.org

1305 sections across all versions Narrow to Django 6.0 (current) →

Topic guide Formsets

BaseFormSet has a couple of methods that are closely related to the ManagementForm, total_form_count and initial_form_count. total_form_count returns the total number of forms in this formset.

dev

empty_form

Topic guide Formsets

BaseFormSet provides an additional attribute empty_form which returns a form instance with a prefix of __prefix__ for easier use in dynamic forms with JavaScript.

dev

Reusable form templates

Topic guide Working with forms

The HTML output when rendering a form is itself generated via a template. You can control this by creating an appropriate template file and setting a custom FORM_RENDERER to use that form_template_name site-wide.

dev

Initial form values

Reference The Forms API

Form.initial Use initial to declare the initial value of form fields at runtime. For example, you might want to fill in a username field with the username of the current session.

4.2 5.0 5.1 5.2 6.0

Model form Meta API

Reference Model forms

classModelFormOptions[source] The _meta API is used to build forms that reflect a Django model. It is accessible through the _meta attribute of each model form, and is an django.forms.models.ModelFormOptions instance.

5.2 6.0

The form rendering API

Reference

Django’s form widgets are rendered using Django’s template engines system. The form rendering process can be customized at several levels: Widgets can specify custom template names. Forms and widgets can specify custom renderer classes.

4.2 5.0 5.1 5.2 6.0

Reusable form templates

Topic guide Working with forms Working with form templates

The HTML output when rendering a form is itself generated via a template. You can control this by creating an appropriate template file and setting a custom FORM_RENDERER to use that form_template_name site-wide.

5.0 5.1 5.2 6.0

Model Form Functions

Reference

Model Form API reference. For introductory material about model forms, see the Creating forms from models topic guide.

4.2 5.0 5.1

Reusable form templates

Topic guide Working with forms Working with form templates

The HTML output when rendering a form is itself generated via a template. You can control this by creating an appropriate template file and setting a custom FORM_RENDERER to use that form_template_name site-wide.

4.2

Write a minimal form

Tutorial Writing your first Django app, part 4

Let’s update our poll detail template (“polls/detail.html”) from the last tutorial, so that the template contains an HTML <form> element: polls/templates/polls/detail.html A quick rundown: The above template displays a radio button for each question choice.

dev

Reference The Forms API

Form.error_css_class Form.required_css_class It’s pretty common to style form rows and fields that are required or have errors. For example, you might want to present required form rows in bold and highlight errors in red.

dev