def all(): id=session.get('uid') print(id) cur.execute("select * from stu where uid=%s",(uid)) result = cur.fetchall() db.commit() return json.dumps(result)
def update(): name=request.args.get("name") age = request.args.get("age") sex = request.args.get("sex") id = request.args.get("id") cur.execute("update stu set name=%s,sge=%s,sex=%s where id=%s",(name,age,sex,id)) db.commit() return "ok"
def add(): name=request.args.get("name") age = request.args.get("age") sex = request.args.get("sex") print(session.get("uid")) cur.execute("insert into stu(name,sge,sex,uid) values(%s,%s,%s,%s)",(name,age,sex,uid)); db.commit() return "ok"
def submit(): uname=request.form["uname"] upsd = request.form["upass"] md5=hashlib.md5() md5.update(upsd.encode()) upsd=md5.hexdigest() cur.execute("insert into user(uname,upsd) values (%s,%s)",(uname,upsd)) db.commit() return redirect("/login")
def delcat(): cid=request.args.get("cid") cur.execute("select * from cat where pid=%s",(cid)) result=cur.fetchone() if(result): return "no" else: cur.execute("delete from cat where cid=%s",(cid)) db.commit() return "ok"
def addcat(): cname=request.args.get("cname") chead = request.args.get("chead") ctype = request.args.get("ctype") uid=request.args.get("uid") pid=request.args.get("pid") cur.execute("insert into cat(cname,chead,ctype,uid,pid) values(%s,%s,%s,%s,%s)",(cname,chead,ctype,uid,pid)) cid=str(db.insert_id()) #在db.commit上边获取 db.commit() return cid
def delete(): id=request.args.get("id") cur.execute("delete from stu where id="+id); db.commit() return "ok"
def updatecat(): cid=request.args.get("cid") cname = request.args.get("cname") cur.execute("update cat set cname=%s where cid=%s",(cname,cid)) db.commit() return "ok"
def addhead(): cid = request.args.get("cid") chead = request.args.get("chead") cur.execute("update cat set chead=%s where cid=%s", (chead, cid)) db.commit() return "ok"
def listadd(): cid = request.args.get("cid") ucon = request.args.get("ucon") cur.execute("insert into info(ucon,cid) VALUES (%s,%s)", (ucon, cid)) db.commit() return "ok"