05:modelform data validation & generating HTML & Database operations

Source: Internet
Author: User
Tags html form

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.