#实现注册用户的功能 @app.post('/register') defregister(): userid = request.args.get("userid", "") name = request.args.get("username", "") password = request.args.get("password", "") question = request.args.get("question", "") question_content = request.args.get("question_content", "") info = (userid, name, password,question,question_content) try: cursor.execute("insert into user (id,username,password,question,question_content) value(%s,%s,%s,%s,%s)", info) conn.commit() return"注册成功,你的用户名是" + name except Exception as e: print(e) return"注册出错了捏"
@app.get('/get_info') defget_info(): username = request.args.get("username", "") cursor.execute("select * from user where username=%s", username) conn.commit() result = cursor.fetchone() print(list(result)) return {"data": list(result)}
# 实现登录验证的功能 @app.route("/login", methods=["POST"]) deflogin(): username = request.form.get("username", "") password = request.form.get("password", "") cursor.execute("select * from user where username=%s and password=%s", (username, password)) conn.commit() result = cursor.fetchone() if result isNone: return"用户名或密码错误" else: return"登录成功"
if __name__ == '__main__': print(app.url_map) app.run(host='0.0.0.0', port=5000)