时间:2021-07-01 10:21:17 帮助过:7人阅读
from flask import * import sqlite3 as sql app = Flask(__name__) @app.route("/") def index(): return render_template("index.html") @app.route("/login") def login(): return render_template("login.html") # @app.route("/login_check") # def login_check(): @app.route("/register",methods=["GET","POST"]) def register(): if request.method == "POST": try: username = request.form["username"] number = request.form["number"] college = request.form["college"] major = request.form["major"] password = request.form["password"] password2 = request.form["password2"] if password != password2: msg = "密码不一致" return render_template("result.html",msg=msg) else: with sql.connect("stu.db") as conn: cur = conn.cursor() cur.execute("INSERT INTO students(username,number,college,major,password) VALUES(?,?,?,?,?)",(username,number,college,major,password)) conn.commit() conn.close() msg = "注册成功" except: conn.rollback() msg = "注册失败" finally: return render_template("result.html",msg=msg) else: return render_template("register.html") @app.route("/admin_login") def admin_login(): return render_template("admin_login.html") @app.route("/list") def list(): return render_template("list.html") if __name__ == "__main__": app.run(debug=True)
[Python-Flask-SQLite]学生管理系统V1.0
标签:exe with rollback port == connect admin into not