from flask import Flask from flask import render_template from flask import request from flask import redirect app = Flask(__name__) @app.route(‘/user‘, methods=["POST", "GET"]) def hello_world(): message = None if request.method == "POST": username = request.form["username"] password = request.form["password"] if not username: message = "please input username" return render_template("index.html", message = message) if not password: message = "please input password" return render_template("index.html", message = message) if username == "jikexueyuan" and password == "123456": return redirect("http://www.baidu.com") else: message = "username or password is wrong" return render_template("index.html", message = message) return render_template("index.html", message = message) if __name__ == ‘__main__‘: app.run(port=8080, debug=True) #index.html <!DOCTYPE html> <html lang="en"> <body> <div align="center"> <h1>user management</h1> </div> <div align="center"> {% if message %} {{ message }} {% endif %} <form name="form1" method="post"> username : <input type="text" name="username" placeholder="username"/> <br/> password : <input type="password" name="password" placeholder="password"/> <br/> <input type="submit" name="submit" value="提交"> <input type="reset" name="reset" value="重置"> </form> </div> </body> <head> <meta charset="utf-8"> <title>user management</title> <script type="text/javascript" src="getValue.js"></script> </head> </html>