Home >Web Front-end >HTML Tutorial >Understand the GET and POST submission methods in the form tag in ten minutes
This article brings you relevant knowledge and comparison of the two submission methods of get and post in the form tag. The function of the form form is to collect the content in the tag,
In the middle, visitors can add text, selections, or some control modules, etc. Then these contents will be sent to the server. I hope it will be helpful to everyone.In HTML, the function of the form form is to collect the content in the tag,< ;form>...
In the middle, the visitor can add text, selections, or some control modules, etc. Then these contents will be sent to the server.
A form must specify two things:
Below Example implementation process:
When we access this interface for the first time, it is the GET method (accessing a URL in the browser is a GET method, no need to explain). Observing the view function, we can see that it renders the form to the user. template page.
When we enter data in the input box and click submit, a POST method will be sent, so that according to the view function, the data entered in the input box will be printed on the console.
Note:
The following example implementation process:
When we access this interface for the first time, it is the GET method (accessing a URL in the browser is a GET method, no explanation is needed). Observing the view function, we can see that it renders to the user with The form template page.
When we enter data in the input box and click submit, the GET method will be sent (because we set the POST submission method in the form form), so that according to the view function, the input box input will be printed on the console The data.
(Because of our settings, clicking the submit button in the template is a GET submission, and the values of a and b submitted by the form form can be printed on the corresponding terminal.)
Note:
The attributes GET and POST of the request object are both QueryDict type objects; Different from python dictionaries, QueryDict type objects are used to handle situations where the same key has multiple values.
For example: How does the backend get the options selected by the user in the multi-select box - use the getlist method!
Construct a GET request-as long as we click the 'click' button, we will find that the function is the same as "②form form usage" "get method" has the same effect. We can also print the values of a and b on the backend (you can also see it by observing the URL link in the browser!), indicating that the data submission is successful!
Recommended tutorial: "html video tutorial"
The above is the detailed content of Understand the GET and POST submission methods in the form tag in ten minutes. For more information, please follow other related articles on the PHP Chinese website!