Home  >  Article  >  Backend Development  >  Detailed example of how Python implements registration and login system

Detailed example of how Python implements registration and login system

黄舟
黄舟Original
2017-08-08 11:29:031697browse

This article mainly introduces in detail the Python3 bank account login system suitable for beginners to learn. It has certain reference value. Interested friends can refer to it.

The form is mainly responsible for the web page Data collection function. A form has three basic components: Form tag: This contains the URL of the CGI program used to process the form data and the method for submitting the data to the server. Form fields: including text boxes, password boxes, hidden fields, multi-line text boxes, check boxes, radio button boxes, drop-down selection boxes and file upload boxes, etc. Form buttons: include submit buttons, reset buttons and general buttons; used to transfer data to CGI scripts on the server or cancel input. Form buttons can also be used to control other processing tasks with defined processing scripts. In HTML, enter a URL in the address bar and open it. This sends a get request. If you want to use a POST request, you need to use a form.

The form in HTML is declared by the form tag. For example:


<form action="login" method="post"> 
 <label>username:</label> 
 <input type="text" name="username"><br /> 
 <label>password:</label> 
 <input type="password" name="password"><br /> 
 <input type="submit" name="submit"> 
<form>

In the above code, the part contained by the form tag is It is the content of the form, focusing on the input part. There are three inputs in this form, one is of text type, representing ordinary text input, one is of password type, representing password input, and one is of submit type, which is a submission button; the form tag defines two attributes, one is action, which represents the path to submit the form, and the other is method, which represents the method for submitting the form. The default is GET. Next, let’s explain the specific process of the above example in detail. When the user clicks the submit button, the browser sends a POST request to the action path. The content of the request is as follows


# is to use the name of each other except Submit as the key value, and the actual filling data is used as a value package, and a post request is sent. If it is changed to get, then a GET request will be sent. Next, the request data received by the server is the same as the data sent from the client program. The next step is to perform corresponding processing based on the data sent and then return.

With the above knowledge in hand, we will start to make a simple registration and login system. The registration and login system we built has a registration function and a login function. After registration, the server stores the registration information locally and verifies whether the registration message is correct when logging in. There are some templates in web.py that already have some support. The specific code is as follows:


data = { 
 &#39;username&#39;:&#39;XXXXXXXX&#39;, 
 &#39;password&#39;:&#39;XXXXXXXX&#39; 
}

The running effect is as follows: If you want to make it more beautiful, you can do it yourself Find some relevant information! What this implements is to enter a password and return a value. You can see that there is no local saving, yes, this is the pit left for you in TODO! Then just remove the comments in the login class above for password matching or something!


Enter your username and password to get:

The above is the detailed content of Detailed example of how Python implements registration and login system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn