djangodocs.org

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

Topic guide Working with forms

The distinction between Bound and unbound forms is important: An unbound form has no data associated with it. When rendered to the user, it will be empty or will contain default values.

dev

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.

4.2 5.0 5.1 5.2 6.0

Reference The Forms API Outputting forms as HTML

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.

4.2 5.0 5.1 5.2 6.0

Reference The Forms API

Form.fields You can access the fields of Form instance from its fields attribute: You can alter the field and BoundField of Form instance to change the way it is presented in the form: Beware not to alter the base_fields attribute …

dev