It is possible to use all types of field models in the forms. Indeed, some types of model fields have been created for a particular use in forms. For example, the TextField
model field has nothing different from CharField
except the fact that by default, in the form, the TextField
field displays a <textarea>
tag and a <input type="text">
name. So, you can write a form field as follows:
field1 = forms.TextField()
The following options are common to all the form fields:
Widgets allow you to define HTML code that renders form fields. We'll explain what widgets can generate as HTML code, as follows:
TextInput
: This corresponds to<input type="text" />
Textarea
: This corresponds to<textarea></textarea>
PasswordInput
: This corresponds to<input type="password" />
RadioSelect
: This corresponds to<input type="radio" />
Select
: This corresponds to<select><option></option></select>
CheckboxInput
: This corresponds to<input type="checkbox" />
FileInput
: This corresponds to<input type="file" />
HiddenInput
: This corresponds to<input type="hidden" />
The following is a partial list of the error messages that can be set when form fields are entered incorrectly:
required
: This message is displayed when the user does not fill data in the fieldmin_length
: This message is displayed when the user has not supplied enough datamax_length
: This message is displayed when the user has exceeded the size limit of a fieldmin_value
: This message is displayed when the value entered by the user is too lowmax_value
: This message is displayed when the value entered by the user is too high