django framework forms the basis -django of form - long-term maintenance -20,200,113

################## form Form #######################

 

 

################## form Form #######################

 

 

################## form Form #######################

 

 

################## form Form #######################

 

 

 

 

1, form components

Prior to web development model, an example to register

  1, there must be a registration page, then there is a form form ----> html codes

  2, the data submitted to the back-end, do check ----> check the validity of data,

  3, check the message, displayed on the page ---> check the information returned, and save the old value

      This shows the error message, you can use ajax way, can also be used to fill a string of way, is the data rendering,

  

  About check:

    1, the front end of the check by js, such as data input did not lose correct format, the front end can all be verified,

    2, need to do the back-end data accuracy,

    Both are there may be no front end, a rear end, but must have a check, the front end js can be bypassed, and can be disabled, so that the rear end of the check must be,

    Front and rear ends are preferably check, so that verification can be a part of the front end, the server can reduce the stress, because some back end does not need to check the retransmission request can be,

::: doubt this case the rear end of the front separation function substantially tasteless ah, less than this function,

 

 

################################################################

2, the use of form components

  1,from django import forms

  2, the definition of a form class

    class reg(forms.Form):

      user=forms.Charfied(max_length=12)

      user=forms.Charfied(max_length=12)  

 

  Generates HTML:

  3, examples of a form object,

  4, passed to the template language.

    Call the corresponding method:

    Three ways:

      1, {{form_obj.as_p}} form of the object method invocation

      2, alone write

        {{  form_obj.pwd.label  }}

        {{  form_obj.pwd  }}

  5, using the form component validator

    from_obj=regForm(request.POST)

    form_obj.is_valid()

3, form the components common fields,

initial initial value, the initial value input box inside.

error_messages

password

radioSelect

Radio Select

Select multiple choice

Radio checkbox

Multi-select checkbox

 

4, form field validation component,

Write a function of the registration page,

User name, password and confirm the password, back-end need to use form components to verify the passwords are the same, after successful authentication, the data needed to be stored in the database,

 

5, form a regular component built validator

Guess you like

Origin www.cnblogs.com/andy0816/p/12186696.html