Simple application of Django forms

Source: Internet
Author: User

Code in views.py:

1  fromDjango.httpImportHttpResponse2  fromDjango.shortcutsImportRender_to_response3  fromDjangoImportForms4 5 classUserForm (forms. Form):6Name =forms. Charfield ()7 8 defRegister (req):9     ifReq.method = ="POST":Ten         #Binding of Form objects Oneform =UserForm (req. POST) A         #Validation of data -         ifform.is_valid (): -             #access to Data the             PrintForm.cleaned_data -             returnHttpResponse ("OK") -     Else: -         #Build Object +form =UserForm () -     returnRender_to_response ("index.html",{"form": Form})
Code in Index.html:
1 <  method= "POST">2    {{form}}3     <    type = "submit" value = "OK" > 4    </form>
When the first visit is a "GET" method, generate the corresponding form object, rendering the interface; When the OK button is clicked, the corresponding "POST" method is the binding of the Form object, the validation of the data, and some other column actions.

Simple application of Django forms

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.