Register and log on to the Python system, and log on to the python system.

Source: Internet
Author: User

Register and log on to the Python system, and log on to the python system.

Forms are mainly responsible for data collection in webpages. A form has three basic components: Form tag, which includes the URL of the CGI program used to process form data and the method for submitting data to the server. Form field: contains the text box, password box, hidden field, multi-line text box, check box, single choice, drop-down selection box, and file upload box. Form button: includes the submit button, reset button, and general button. It is used to send data to the CGI script on the server or cancel the input, you can also use the form button to control the processing of other defined scripts. In HTML, enter a URL in the address bar and open it. In this way, a get request is sent. To use a POST request, a form is required.

The form in HTML is declared by the form label. 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 code above, the part contained by the form tag is the content of the form, and the input part is followed. The form contains three inputs, one of which is of the text type, it indicates a common text input, a password, a password, a submit, and a submit button. The form tag defines two attributes, one being action, indicates the form submission path. method indicates the form submission method. The default value is GET. Next, let's explain in detail the specific process of the above example. When the user clicks the submit button, the browser sends a POST request to the action path, the request content is as follows:

data = {  'username':'XXXXXXXX',  'password':'XXXXXXXX' } 

The name of each input except the submit is used as the key value, and the actual data filled in is used as the value as the data packet. a POST request is sent. Of course, if the method is changed to get, then the GET request is sent. Next, the request data received by the server is the same as the data sent from the client program. Next, process the sent data and return it.

With the above knowledge, we will start a simple registration and login system. The registration and logon functions are available in the registration and logon systems. After registration, the server stores registration information locally and verifies that the registration message is correct during logon. Some templates in web. py already have some support. The specific code is as follows:

# -*- coding: cp936 -*- import web import os  urls = (  '/', 'hello',  '/login', 'login',  '/regist', 'regist' ) app = web.application(urls, globals()) class hello:  def __init__(self):   self.render = web.template.render('templates/')  def GET(self):   return self.render.form()   class login:  def POST(self):   para = web.input()   username = para['username']   password = para['password']    #TODO:...   #if authenticate(username,password):    #return render.hello(username)   return 'hello world'  class regist:  def GET(self):   return 'hello world'   #return self.render.form()  def POST(self):   para = web.input()   username = para['username']   password = para['password']    #TODO:...   return 'hello world'  if __name__ == '__main__':  app.run() 

The running effect is shown in a drop chart: If you want to make yourself more beautiful, you can find some relevant information on your own! In this case, enter the password and return the value. You can see that there is no local storage, yes, this is the trap left for you in TODO! Then, just remove the comments from the above login class for password matching!


You can enter the user name and password at will:

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

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.