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:
-
class passwordinput
-
password input:
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:
-
class multiplehiddeninput
- multiple widgets.
-
class fileinput
- file upload input:
-
class dateinput
-
new in django 1.1:
date input as a simple text box:
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
-
new in django 1.0:
date/time input as a simple text box:
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:
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:
-
class checkboxinput
-
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:
requires that your field provides choices.
-
class nullbooleanselect
- select widget with options ‘unknown’, ‘yes’ and ‘no’
-
class selectmultiple
-
select widget allowing multiple selection:
requires that your field provides choices.
-
class radioselect
-
a list of radio buttons:
requires that your field provides choices.
-
class checkboxselectmultiple
-
a list of checkboxes:
-
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())