一、主要程序 app.py
from flask import Flask, render_template, request,flash import pymysql app = Flask(__name__) app.secret_key='asdfads' #消息传递需要加密
@app.route('/a12',methods=["GET","POST"]) def a12(): if request.method=="POST": username=request.form.get ('username') password = request.form.get('password') password2 = request.form.get('password2') print([username,password,password2]) if not all ([username,password,password2]): flash(u"用户名或密码不完整") elif password!=password2: flash(u"两次密码不一致") else: flash(u"密码和账号都输入正确,恭喜你!") return render_template("a12.html") if __name__ == '__main__': app.run(host="0.0.0.0", port=5000, debug=True)
二、前端页面 '/templates/a12.html'
<html lang="cn-zh"> <body> <form action="a12" method="post" > <table class="table table-bordered" align="center"> <tr><td>用户名:</td><td><input type="text" name="username" value=""></td></tr> <tr><td>密码:</td><td><input type="password" name="password" value=""></td></tr> <tr><td>确认密码:</td><td><input type="password" name="password2" value=""></td></tr> <tr><td colspan="2"><input type="submit" value="submit" align="right"></td></tr> <tr> <td colspan="2"> {% for message in get_flashed_messages() %} <font color="blue" >{{message }}</font> {% endfor %} </td> </tr> </table> </form> </body> </html>