Effect and basic use of 1.1 modelform
1. Form function
1. function 1: Verify
2. function 2: Generate HTML Tag (default function: Keep last committed value)
3. Function 3: data operation
4. Function 4: HTML form submission holds last commit data
5, function 5: Initialize the content of the page display
2. Form Use principle
1 , new URL mode operation (be sure to use form to generate HTML, to avoid the submission of the Refresh page, missing the current page filled values)
2 , the AJAX request can not generate HTML tags without form, only the form for validation, because the AJAX request itself does not refresh the page, do not have to worry about filling
Value is lost, and it is possible to generate HTML using a form
1.2
field types that can be defined in Meta
Note: Import Module names (fields, widgets) and field names are duplicated, so an individual name is required for import.
fromDjangoImportForms fromDjango.formsImportFields as ffields fromDjango.formsImportWidgets as FwidgetsclassUserinfomodelform (forms. Modelform): IS_RMB= Ffields.charfield (widget=fwidgets.checkboxinput ())classMeta:model=models. UserInfo Fields='__all__' #Fields = [' username ', ' email '] #exclude = [' username ']Labels = { 'username':'User name', 'Email':'Email',} help_texts= { 'username':'...'} widgets= { 'username': Fwidgets.textarea (attrs={'class':'C1'})} error_messages= { '__all__':{#Overall error message }, 'Email': { 'Required':'The mailbox cannot be empty', 'Invalid':'Bad mailbox format :', } } Field_classes= {#what is the class that defines the field #' email ': Ffields.urlfield # Here you can only fill in the class, and parentheses are the object. } #localized_fields= (' CTime ',) # which fields are localized
field types that can be defined in Meta
05:modelform data validation & generating HTML & Database operations