Widgets¶
A widget is Django’s representation of a HTML input element. The widget
handles the rendering of the HTML, and the extraction of data from a GET/POST
dictionary that corresponds to the widget.
Django provides a representation of all the basic HTML widgets, plus some
commonly used groups of widgets:
-
class TextInput¶
- Text input: <input type='text' ...>
-
class PasswordInput¶
-
Password input: <input type='password' ...>
Takes one optional argument:
-
render_value¶
- Determines whether the widget will have a value filled in when the
form is re-displayed after a validation error (default is True).
-
class HiddenInput¶
- Hidden input: <input type='hidden' ...>
-
class MultipleHiddenInput¶
- Multiple <input type='hidden' ...> widgets.
-
class FileInput¶
- File upload input: <input type='file' ...>
-
class DateInput¶
-
Date input as a simple text box: <input type='text' ...>
Takes one optional argument:
-
format¶
- The format in which this field’s initial value will be displayed.
If no format argument is provided, the default format is '%Y-%m-%d'.
-
class DateTimeInput¶
-
Date/time input as a simple text box: <input type='text' ...>
Takes one optional argument:
-
format¶
- The format in which this field’s initial value will be displayed.
If no format argument is provided, the default format is '%Y-%m-%d
%H:%M:%S'.
-
class TimeInput¶
-
Time input as a simple text box: <input type='text' ...>
Takes one optional argument:
-
format¶
- The format in which this field’s initial value will be displayed.
If no format argument is provided, the default format is '%H:%M:%S'.
Changed in Django 1.1: The format argument was not supported in Django 1.0.
-
class Textarea¶
- Text area: <textarea>...</textarea>
-
class CheckboxInput¶
-
Checkbox: <input type='checkbox' ...>
Takes one optional argument:
-
check_test¶
- A callable that takes the value of the CheckBoxInput
and returns True if the checkbox should be checked for
that value.
-
class Select¶
-
Select widget: <select><option ...>...</select>
Requires that your field provides choices.
-
class NullBooleanSelect¶
- Select widget with options ‘Unknown’, ‘Yes’ and ‘No’
-
class SelectMultiple¶
-
Select widget allowing multiple selection: <select
multiple='multiple'>...</select>
Requires that your field provides choices.
-
class RadioSelect¶
-
A list of radio buttons:
<ul>
<li><input type='radio' ...></li>
...
</ul>
Requires that your field provides choices.
-
class CheckboxSelectMultiple¶
-
A list of checkboxes:
<ul>
<li><input type='checkbox' ...></li>
...
</ul>
-
class MultiWidget¶
- Wrapper around multiple other widgets
-
class SplitDateTimeWidget¶
-
Wrapper around two widgets: DateInput for the date, and TimeInput
for the time.
Takes two optional arguments, date_format and time_format, which
work just like the format argument for DateInput and TimeInput.
Changed in Django 1.1: The date_format and time_format arguments were not supported in Django 1.0.
-
class SelectDateWidget¶
-
Wrapper around three select widgets: one each for month, day, and year.
Note that this widget lives in a separate file from the standard widgets.
from django.forms.extras.widgets import SelectDateWidget
date = forms.DateField(widget=SelectDateWidget())