Django form processing (1) -- simplest form

Source: Internet
Author: User

It is time to process django forms.

The simplest form processing method is to extract strings from the input box and hand them to the background for data processing and return the corresponding results.

Based on the principle of getting started, the form designed today has only one text box and one button.

Create a new test01.html file under the templatesdirectory

<! DOCTYPE html> 

Next, add the following code in views. py:

From django. shortcuts import render_to_responsedef test (request): query = request. GET. get ('Q', '') # request. GET is a dictionary-like object that contains all GET request parameters. Here, it indicates obtaining the parameter value of 'q' if query: results = 'you just sent % s' % queryelse: results = [] return render_to_response('test01..html ', {'result': results })

 

In addition, add :( R' ^ test/', 'test') in urls. py '),

Open 127.0.0.1: 8000/test/in the browser/

Running result:


This completes the most simple data submission.

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.