Getting Started with Python web py (12)-Implementing a User Login forum

Source: Internet
Author: User
Tags set cookie
has already introduced how to register the user, when the user registers successfully, needs to use the account to log in, this login process is how realizes.
The first is to have a login connection, through the first click on the login, will enter the login URL connection: Http://127.0.0.1:8080/login, when you click on the Web page, you will be in the WEBPY application process this connection:
'/login ', ' login ', #登录

Yes, this is the place to associate, and then go to the login handler class:

Class Login:
    def get (self): return
        titled_render (' login '). Login ()

    def POST (self):
        i = web.input ( Username= ', password= ')
        user_id = model. User (). Login (I.username, I.password)
        if user_id:
            # Set Cookie
            web.setcookie (' user_id ', str (user_id), Settings. Cookie_expires)
            raise Web.seeother ('/user/%d '% user_id)
        else: return
            Titled_render (). Failed (' Logon verification failed, Please check that the account and password are correct ")
The login page will be displayed first, as follows:

Here, in fact, is the method of calling get, More directly using the login.html template to return to the browser, when you enter the user name and password, you will post the data from the browser sent to the server, and then in the Webpy can receive the user name and password, respectively, in I.username, In the I.password. Call model. User (). The login function confirms the existence of the user by means of a database, and the password is correct, and if it is correct, it can be stored in the browser's cookie, and all subsequent processing can be judged according to the ID in the cookie.

Supporting the source code in: http://download.csdn.net/download/caimouse/10255258

TensorFlow API Introduction
http://edu.csdn.net/course/detail/4495
Basic tutorials for getting started with TensorFlow
http://edu.csdn.net/course/detail/4369
C + + Standard Template Library from getting started to mastering
http://edu.csdn.net/course/detail/3324
Learn C + + with old rookie
http://edu.csdn.net/course/detail/2901
Learn Python with old rookie.
http://edu.csdn.net/course/detail/2592

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.