In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the use of form tag GET and POST in HTML, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
GET and POST in form tags
In HTML, the role of form forms is to collect the contents of tags,... In the middle, visitors can add something like text, selection, or some control module, etc. The content will then be sent to the server.
A form must specify two things:
The method parameter of form is used to set the way the form is submitted, which defaults to POST.
Action is used to set the submission url of the form. If the string is not written or left empty, the current URL. Exe will be used.
An example of a ① form form submitted using post:
The following example implements the process:
when we visit this API for the first time, it is in GET mode (accessing a URL in the browser is a GET method, and there is no need to explain it). By observing the view function, we can see that it renders a template page with a form form to the user.
When we enter the data in the input box and click submit, it will be sent in POST mode, so that the data entered in the input box will be printed in the console according to the view function.
Note:
The submission method of post does not display parameters in url
The submitted data can be obtained through request.POST.get.
An example of a ② form form submitted using get:
The following example implements the process:
when we visit this API for the first time, it is in GET mode (accessing a URL in the browser is a GET method, and there is no need to explain it). By observing the view function, we can see that it renders a template page with a form form to the user.
When we enter the data in the input box and click submit, we will send the GET mode (because we set the POST submission mode in the form form), so that according to the view function, the data entered in the input box will be printed in the console.
Because of our settings, clicking the submit button in the template is a GET submission, and the values of an and b submitted by the form form can be printed at the corresponding terminal. )
Note:
The parameters submitted by get will be displayed in url
You can get the submitted parameters through the method of request.GET.get.
③ one-key multi-valued getlist method:
The properties GET and POST of request object are objects of type QueryDict.
Unlike python dictionaries, objects of type QueryDict are used to handle situations where the same key has multiple values.
Method get ():
According to the value of the key, only one value of the key can be obtained
If a key has multiple values at the same time, get the last value (because it is overridden! )
Method getlist ():
Returns the value of the key as a list according to the key obtained value
You can get multiple values of a key
For example: how does the back end use the getlist method by getting the option selected by the multi-box user!
Properties of the GET and POST objects in ④ request: the first: the GET property!
Objects of type QueryDict
Contains all the parameters of the get request method
Corresponding to the parameters in the url request address, located at? behind
Parameters are in the format of key-value pairs, such as key1=value1
Between multiple parameters, use & to connect, such as key1=value1&key2=value2
Second: the POST attribute!
Objects of type QueryDict
Contains all the parameters of the post request method
Corresponds to the controls in the form form
If the control in the form has a name attribute, the value of the name property is the key, and the value of the value property is the value, which constitutes a key-value pair submission.
For checkbox controls, the name property is also a group, which will be submitted when the control is selected, and there are multiple values with one button.
Small expansion:
Construct a GET request-as long as we click the "Click" button, we will find that the effect is exactly the same as "② form forms use get". We can also print the values of an and b on the back end (you can also see the URL link in the browser. ), indicating that the data was submitted successfully!
Summary of ⑤ GET and POST request methods:
GET:GET, like its name, takes data from the server, does not change the server's state and data, and sends parameters to the server in URL.
POST sends a certain amount of data to the server and generally changes the server's data.
The parameters of the POST method can not be seen in the URL, it is passed to the server through the body parameters, so it is safer than the GET method to see the passed parameters directly in the URL. Of course, we can't simply judge that the POST method is more secure than the GET method, and more security processing is needed to keep the website safe.
Thank you for reading this article carefully. I hope the article "what is the use of GET and POST of form tags in HTML" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.