One: Common Fields
1, the built-in fields Django Form class as follows:
To hold regular expression ChoiceField ***** MultipleChoiceField CharField IntegerField DecimalField DateField DateTimeField EmailField GenericIPAddressField FileField RegexField
Detailed field
Field, required = True, whether to allow null widget = None, HTML plug label = None, or for generating a display content Label Label initial = None, initial value help_text = '', help information (shown next to the label) error_messages, = None, error message { 'required': 'not empty', 'invalid': 'malformed'} show_hidden_initial = False, whether the current plus a hidden behind the plug and the plug has a default value (which may be used to test whether the two input been) validators = [], custom validation rules localize = False, whether to support the localization disabled = False, if you can edit label_suffix = None Label contents suffix CharField (Field,) max_length = None, the maximum length of min_length = None, minimum length strip = True whether to remove the user input blank IntegerField (Field,) MAX_VALUE = None, maximum min_value = None, minimum FloatField (IntegerField) ... DecimalField (IntegerField) MAX_VALUE = None, maximum min_value = None, minimum max_digits = None, total length decimal_places = None, decimals bit length BaseTemporalField (Field,) input_formats = None time format DateField (BaseTemporalField) format: 2015-09-01 TimeField (BaseTemporalField) format:. 11: 12 is DateTimeField (BaseTemporalField) format: 2015-09-01 11:12 DurationField (Field,) time interval:% D% H:% M:% F% S. ... RegexField (as CharField) REGEX, custom regex max_length = None, maximum length min_length = None, minimum length error_message = None, ignore the error message used = {error_messages, 'invalid': '...'} EmailField (as CharField) ... the FileField ( Field,) allow_empty_file = False whether to allow an empty file the ImageField (the FileField) ... Note: PIL module needs, pip3 install Pillow when two or more dictionaries used, two things should be noted: - form form enctype = "multipart / form-data " - view the MyForm = function obj (of request.POST, request.FILES) URLField (Field,) ... BooleanField (Field,) ... NullBooleanField (BooleanField) ... ChoiceField (Field,) ... choices = (), options such as: choices = ((0, 'Shanghai'), (1, 'Beijing'),) required = True, if required widget = None, plug-in, select the default plug- label = None, Label content initial = None, the initial value help_text = '', help tips ModelChoiceField (ChoiceField) ... django.forms.models.ModelChoiceField QuerySet, # query data in the database empty_label = "---------", # empty default display content to_field_name = None, # HTML corresponding to the value in the value field limit_choices_to = None # ModelForm secondary screening QuerySet ModelMultipleChoiceField (ModelChoiceField) ... django.forms.models.ModelMultipleChoiceField TypedChoiceField (ChoiceField) coerce = lambda val: val be the value of the selected conversion default values empty_value = '' null MultipleChoiceField (ChoiceField) ... TypedMultipleChoiceField (MultipleChoiceField) coerce = lambda val: val for each selected value is a conversion empty_value = 'default null values ComboField (Field,) Fields = () using a plurality of verification, as follows: i.e., the maximum length of 20 validation, verification and mailbox format fields.ComboField (fields = [fields.CharField (max_length = 20), fields. EmailField (),]) MultiValueField (Field,) the PS: abstract class, subclass, the polymerization can be implemented to match a value of a plurality of dictionaries to use with MultiWidget input_time_formats = None list format: ['% H:% m :% S ','% H:% m: % S.%f', '%H:%M'] SplitDateTimeField (MultiValueField) input_date_formats = None, list format: [ '% the Y -% m -% D', 'D%% m /% the Y', '% m /% D /% Y'] that FilePathField will (ChoiceField) file option, directory the file appears on the page path, the folder path to match = None, regular matching recursive = False, recursively following folder allow_files = True, allows files allow_folders = False, allowing the folder required = True, the widget = None, label = None , Initial = None, help_text = '' GenericIPAddressField Protocol = 'both-', both-, ipv4, ipv6 support IP format unpack_ipv4 = False resolve ipv4 address, if it is :: ffff: 192.0.2.1 when resolves to 192.0.2.1, PS: protocol must be enabled in order to both SlugField (CharField) numbers, letters, underscores, minus (hyphen) ... UUIDField (CharField) uuid type
Two: Django built-ins
TextInput(Input) NumberInput(TextInput) EmailInput(TextInput) URLInput(TextInput) PasswordInput(TextInput) HiddenInput(TextInput) Textarea(Widget) DateInput(DateTimeBaseInput) DateTimeInput(DateTimeBaseInput) TimeInput(DateTimeBaseInput) CheckboxInput Select NullBooleanSelect SelectMultiple RadioSelect CheckboxSelectMultiple FileInput ClearableFileInput MultipleHiddenInput SplitDateTimeWidget SplitHiddenDateTimeWidget SelectDateWidget
Common select the plug
# A single radio, a string value # = fields.CharField User ( # Initial = 2, # = widgets.RadioSelect the widget (choices = ((. 1 'Shanghai'), (2 'Beijing'))) #) # a single radio, a string value # = fields.ChoiceField User ( # choices = ((. 1 'Shanghai'), (2 'Beijing'),), # = Initial 2, # = widgets.RadioSelect the widget #) # single select, the string value # = fields.CharField User ( # Initial = 2, # = widgets.Select the widget (choices = ((. 1 'Shanghai'), (2 'Beijing'))) #) # single select, the string value # = fields.ChoiceField User ( # choices = ((. 1 'Shanghai'), (2 'Beijing'),), # = Initial 2, # = the widget Widgets.The SELECT #) # multiple choice select, value list User fields.MultipleChoiceField = # ( # = choices ((. 1 'Shanghai'), (2 'Beijing'),), # Initial = [. 1,], # = widgets.SelectMultiple the widget #) # single CheckBox # User fields.CharField = ( # = widgets.CheckboxInput the widget () #) # CheckBox multiple choice, value list # = fields.MultipleChoiceField User ( # Initial = [2,], # choices = ((. 1, 'Shanghai'), (2, 'Beijing'),), # = widgets.CheckboxSelectMultiple the widget #)
Reference; http: //www.cnblogs.com/liaoboshi/p/6576188.html
Reference; http: //www.cnblogs.com/liaoboshi/p/6576188.html