数据处理逻辑
python
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"<html><body>Welcome {username}</body></html>"
else:
return f"<html><body>Welcome!</body></html>"
if __name__ == '__main__':
app.run(debug=True)
前端代码
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GET and POST</title>
</head>
<body>
<form action = "http://localhost:5000" method = "post">
<table>
<tr>
<td>Name</td>
<td><input type ="text" name ="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type ="password" name ="password"></td>
</tr>
<tr>
<td><input type = "submit"></td>
</tr>
</table>
</form>
</body>
</html>
两个文件在同目录下,运行py文件即可。