Django Book Notes---form forms

Source: Internet
Author: User

     First look at the following simple method: From django.http import httpresponsedef hello (Request ):     return httpresponse ("Hello world")      We can get a lot of information     request from this request. meta  is a Python dictionary that contains header information for all HTTP requests, such as the user's IP address and user agent (usually the name and version number of the browser).   Note that the complete list of header information depends on the header information sent by the user and the header information for the server-side settings.   Several common key values in this dictionary are:     http_referer, pre-pit link page, if any.   (Please note that it is referrer's clerical error.) )     http_user_agent, the user-agent string of the user's browser, if any.   For example: "mozilla/5.0  (x11; u; linux i686; fr-fr; rv:1.8.1.17)  Gecko/ 20080829 firefox/2.0.0.17 " .    REMOTE_ADDR  client IP, such as:" 12.345.67.89 " . (If the request is a proxy server, it may be a comma-separated number of IP addresses, such as: "12.345.67.89,23.456.78.90"  .)      use the Get method to access a key value      ua = request that may not exist. Meta.get (' http_user_agent ',  ' unknown ')    &nbspThe data using the Get method is passed through the query string (for example,/search/?q=django), so we can use Requet. Get to get these data: request.get[' Q '] Create your own form class: >>> from contact.forms import contactform >>> f = contactform () >>> print f<tr><th><label  For= "Id_subject" >subject:</label></th><td><input type= "text"  name= "subject"  id= "Id_subject"  /></td></tr><tr><th><label for= "Id_email" > Email:</label></th><td><input type= "text"  name= "email"  id= "Id_email"   /></td></tr><tr><th><label for= "Id_message" >Message:</label></ Th><td><input type= "text"  name= "message"  id= "Id_message"  /></td></ tr> default output is table format, we can also output UL, p format print f.as_ul () print f.as_p () to create a form>>> f =  contactform ({' Subject ':  ' Hello ',  ' email ':  ' [email protected] ',  ' message ':  ' nice site! '}) >>> f.is_boundtrue>>> f.is_valid ()      Verify that the data is valid true to view the error message for the form: >>> f = contactform ({' Subject ':  ' Hello ',  ' message ':  '}) >>>  f[' message '].errors[u ' this field is required. ' >>> f[' subject '].errors[]>>> f[' email '].errors[] Cleanup data: >>> f.cleaned_ Data{message ':  unice site!, email: [email protected], subject: uhello}







This article from "Leboit" blog, declined reprint!

Django Book Notes---form 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.