def selectcat(): global arr arr=[] cur.execute("select * from cat") result=cur.fetchall() results=digui(result,0) return json.dumps(results)
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 jian(): uname=request.form["uname"] cur.execute("select * from user where uname=%s",(uname)) result=cur.fetchone() if(result): return "false" else: return "true"
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 login1(): uname = request.form["uname"] upsd = request.form["upass"] md5 = hashlib.md5() md5.update(upsd.encode()) upsd = md5.hexdigest() cur.execute("select * from user where uname=%s and upsd=%s",(uname,upsd)) result=cur.fetchone() global uid uid=result["id"] if(result): session["login"] = "******" session["uid"] = result["id"] session["uname"] = result["uname"] res=make_response(redirect("/")) return res else: return redirect("/logup")
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 selecthead(): cid = request.args.get("cid") cur.execute("select chead from cat where cid=%s", (cid)) result = cur.fetchone() result = result["chead"] return result
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"
def listselect(): cid = request.args.get("cid") cur.execute("select * from info where cid=%s", (cid)) result = cur.fetchall() return json.dumps(result)