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.