from flask import Flask, abort, make_response, request, render_template
app = Flask(__name__)
# 重定向到百度
@app.route('/index', methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template("index.html")
if request.method == "POST":
name = request.form.get('name')
password = request.form.get('password')
if name == 'zhangsan' and password == '123':
return '登录成功'
else:
abort(404)
if __name__ == '__main__':
app.run(debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post">
账号:
<input type="text" name="name">
<br>
密码:
<input type="password" name="password">
<br>
<input type="submit" name="submit">
</form>
</body>
</html>
效果
提交成功
提交失败、