Flask implement user login interface

# Coding: UTF8 
# a lead packet, session storage bag, rendering module and the request packet 
from Flask Import the Flask, the render_template, Request, the session 

App = the Flask (__ name__) # instantiate the Flask, passing name 

# construct a web server, print hello / world / 
@ app.route ( "/") # set routing (url distributor) 
# 127.0.0.1:5000/ complete url 
DEF Web (): 
# Home information 
# username to log in successfully saved session inside 
    if 'username' the session in: 
        return "user has logged in" 
    return "Login failed ..." 
# display text 
@ app.route ( "/ context") 
DEF index (): 
# formatting text 
    return "<h1 style = 'color : blue' > the Web the Hello! --Flask </ h1 of> " 

# business logic and presentation phases were separated 
@ app.route ( '/ login /' , methods = [" POST "," GET "]) # Using the HTTP method, GET: access to resources POST: creates a resource 
def login ():
    # Call request form inside information table to obtain username user name 
    username = request.form.get ( 'username') 
    password = request.form.get ( 'password') 
    # verify 
    if username == "User" and password = = "123456": 
        # stored login information saved to the session the dictionary 
        session [ 'username'] = username 
        session [ 'password'] = password 
        return "a successful login" 
    # Create a html file, rendering module 
    return render_template ( 'login. HTML ') 

@ app.route (' / Zimbabwe Logout ') 
# exit account 
DEF Zimbabwe Logout (): 
    session.pop (' username ') 
    return' to exit the account! ' 
# Set key 
app.secret_key =' the ABC ' 

IF the __name__ ==' __main__ ':
Published 58 original articles · won praise 31 · views 40000 +

Guess you like

Origin blog.csdn.net/qq_37504771/article/details/82833231