flask Login

# -*- coding:gb2312 -*-
#!/usr/bin/python
# Filename: show_post.py
from flask import request
from flask import Flask
from flask import render_template

app = Flask(__name__)

@app.route('/')
def index():
    return 'Index Page'

@app.route('/hello')
def hello():
    return 'Hello~World~'

@app.route('/user/<username>')
def show_user_profile(username):
    # show the user profile for that user
    return 'User %s' % username

@app.route('/post/<int:post_id>')
def show_post(post_id):
    # show the post with the given id, the id is an integer
    return 'Post %d' % post_id

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        return do_the_login()
    else:
        return show_the_login_form()

def do_the_login():
    username = request.form['username'];
    password = request.form['password'];
    print "username:" , username
    print "password:" , password
    return render_template('login_result.html',username=username,password=password)

def show_the_login_form():
    return render_template('login_form.html')


if __name__ == '__main__':
    app.run(debug=True)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> templates/login_form.html </title>
  <meta charset="UTF-8">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>

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

 </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> templates/login_result.html </title>
  <meta charset="UTF-8">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>

 <h3>Name: {{ username }}</h3>
 <h3>Password: {{ password }}</h3>
 <br>

 </body>
</html>

 

posted @ 2018-01-30 10:23  sky20080101  阅读(100)  评论(0)    收藏  举报