- from flask import Flask, request
-
- app = Flask(__name__)
-
-
- @app.route('/', methods=['POST'])
- def index():
- username = request.form['username']
- password = request.form['password']
- if username == "Jhon" and password == "1":
- return f"Welcome {username}"
- else:
- return f"Welcome!"
-
-
- if __name__ == '__main__':
- app.run(debug=True)
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>GET and POSTtitle>
- head>
- <body>
- <form action = "http://localhost:5000" method = "post">
- <table>
- <tr>
- <td>Nametd>
- <td><input type ="text" name ="username">td>
- tr>
- <tr>
- <td>Passwordtd>
- <td><input type ="password" name ="password">td>
- tr>
- <tr>
- <td><input type = "submit">td>
- tr>
- table>
- form>
- body>
- html>
两个文件在同目录下,运行py文件即可。