一、python代码
from flask import Flask,render_template,request
app = Flask(__name__)
@app.route('/',methods=['GET','POST'])
def view_template():
if request.method=='POST':
username = request.form.get('username')
password = request.form.get('password')
password2 = request.form.get('password2')
print(username)
if not all([username,password,password2]):
print("参数不完整")
elif password !=password2:
print("密码不相同")
else:
return "success"
return render_template('myhtml.html')
if __name__=='__main__':
app.run()
二、myhtml.html文件内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flask框架测试</title>
</head>
<body>
<form method="post">
<label>用户名:</label><input type="text" name="username"><br>
<label>密码:</label><input type="password" name="password"><br>
<label>确认密码:</label><input type="password" name="password2"><br>
<input type="submit" value="提交"><br>
</form>
</body>
</html>