def add_carouse(): """ 增加轮播图 :arg {"type":0, "imgId":1,"status":1,"content":"", "url":"http://www.google.com/", "token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"} :arg {"type":1, "imgId":1,"status":1,"content":"123", "url":"","token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"} :return: json """ carouse_info = request.get_json() url = carouse_info.get("url") type = carouse_info.get("type") img_id = carouse_info.get("imgId") status = carouse_info.get("status") content = carouse_info.get("content") create_date = get_current_time() # 参数校验,如果type为0,url不能为空;如果如果为1,content不能为空 if type != None and type == 0: paras = [type, img_id, status, url] else: paras = [type, img_id, status, content] if not _admin_parameters_filter(paras): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 构造sql并执行 insert_anno_sql = "INSERT into tbl_carouse " \ "values(NULL, %d, %d, %d, '%s', '%s', '%s')" % (type, img_id, status, content, url, create_date) if excute(insert_anno_sql): return json(get_json(msg="添加成功!")) return json(get_json(code=-100, msg="添加失败,请检查数据库链接!"))
def user_regist(): """ 用户注册 :arg {"username":"******", "password":"******", "nickname":"nickname"} :return json """ user_info = request.get_json() nickname = user_info.get("nickname") username = user_info.get("username") password = user_info.get("password") create_date = get_current_time() # 参数校验 if not _parameters_filter([username, password, nickname]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 判断用户名是否已被占用 query_user_sql = "select * from tbl_user where username='******'" % username if query(query_user_sql): return json(get_json(code=-300, msg="用户名已存在!")) # 没被占用,进行注册 user_reg_sql = "insert into tbl_user values(NULL, '%s', '%s', '%s'," \ "NULL, 1,'','','',NULL,'','','','',NULL,'','%s',NULL)" % (username, password, nickname, create_date) if excute(user_reg_sql): return json(get_json(msg="注册成功!")) return json(get_json(code=-100, msg="注册失败,用户名可能已经存在了!"))
def add_user(): """ 新增用户 :arg {"username":"******", "password":"******", "nickname":"nickname", "token": "4cmhr7a8-t0zw-sskr-3e5i-o9sdxv48878p"} :return: json """ user_info = request.get_json() nickname = user_info.get("nickname") username = user_info.get("username") password = user_info.get("password") create_date = get_current_time() # 参数校验 if not _admin_parameters_filter([username, password, nickname]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 判断用户名是否已被占用 query_user_sql = "select * from tbl_user where username='******'" % username if query(query_user_sql): return json(get_json(code=-300, msg="用户名已存在!")) # 没被占用,进行注册 user_reg_sql = "insert into tbl_user values" \ "(NULL, '%s', '%s', '%s',NULL,1,'','','',NULL,'','','','',NULL,'','%s',NULL)" \ % (username, password, nickname, create_date) print(user_reg_sql) if excute(user_reg_sql): return json(get_json(msg="新增用户成功!")) return json(get_json(code=-100, msg="新增用户失败!"))
def cancel_article_like(): """ 取消文章点赞 :arg {"articleId":1,"token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"} :return: """ article_info = request.get_json() article_id = article_info.get("articleId") # 参数校验 if not _parameters_filter([article_id]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 检查是否已经赞过了 user_id = session.get("user").get("id") query_article_like_detail = "select * from tbl_article_like as a " \ "where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id) if not query(query_article_like_detail): return json(get_json(code=-100, msg="您还没有赞过此文章!")) # 修改状态 update_article_like_sql = "update tbl_article_like as a set " \ "a.status=0 where a.userId=%d and a.articleId=%d" % (user_id, article_id) if excute(update_article_like_sql): return json(get_json(msg="成功取消此文章的点赞!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def reply_comment(): """ 回复评论 :arg {"articleId":1, "commentId":5, "commentContent":"test","token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"} :return: json """ comments_info = request.get_json() article_id = comments_info.get("articleId") comment_id = comments_info.get("commentId") comment_content = comments_info.get("commentContent") # 参数校验 if not _parameters_filter([article_id, comment_id, comment_content]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 文章下是否有此评论,这里有bug todo # 增加文章评论 user_id = session.get("user").get("id") insert_reply_comment_sql = "insert into tbl_article_comment values" \ "(NULL, %d, %d, '%s', 1, '%s', NULL, %d)" % \ (user_id, article_id, comment_content, get_current_time(), comment_id) if excute(insert_reply_comment_sql): return json(get_json()) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def article_collect(): """ 收藏文章 :arg {"articleId":1,"token": "xx13v9wp-t4gl-gsxn-mnd6-ftnhx6gnp3r0"} :return: json """ article_info = request.get_json() article_id = article_info.get("articleId") # 参数校验 if not _parameters_filter([article_id]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 检查是否已经收藏过文章 user_id = session.get("user").get("id") query_article_collect_detail = "select * from tbl_article_collect as a " \ "where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id) if query(query_article_collect_detail): return json(get_json(code=-100, msg="您已经收藏过此文章了!")) # 检查是否存在文章 query_article_sql = "select * from tbl_article where id=%d and status=1" % article_id if not query(query_article_sql): return json(get_json(code=-100, msg="文章不在了...!")) # 增加文章收藏记录 insert_article_collect_sql = "insert into tbl_article_collect " \ "values(NULL, %d, %d, 1, '%s', NULL )" % (user_id, article_id, get_current_time()) if excute(insert_article_collect_sql): return json(get_json(msg="收藏文章成功!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def upload(): """ 公共上传资源接口 :arg file:上传文件格式;source:图片资源,详细请求数据参见uploadDemo.html :return: """ # 检验来源 file_source = request.form.get("source") if not _parameters_filter([file_source]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 保存图片文件到服务器 file = request.files['file'] file_name = create_token() + "." + file.filename.split(".")[1] if _upload_files(file, file_name): # 执行插入数据库操作 insert_img_source_sql = "INSERT INTO tbl_image_sources " \ "values(NULL, '%s', 1, '%s', NULL)" % (file_name, get_current_time()) # 执行成功返回该img信息 if excute(insert_img_source_sql): query_img_sql = "select * from tbl_image_sources where path='%s'" % file_name datas = {"imgInfo": query(query_img_sql)} return json(get_json(data=datas)) return json(get_json(code=-100, msg="操作失败!"))
def add_article(): """ 新增文章 :arg { "title":"title", "imgId":1,"type":2, "content":"test", "source":"123","token": "6gax71xs-z38o-8178-3a2t-6c3jjcm2cn18" } :return: json """ article_info = request.get_json() type = article_info.get("type") title = article_info.get("title") img_id = article_info.get("imgId") source = article_info.get("source") content = article_info.get("content") user_id = _get_admin_session()["adminInfo"]["id"] # 参数校验 if not _admin_parameters_filter([title, img_id, type, content, source]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 插入文章记录 insert_article_sql = "INSERT INTO tbl_article VALUES" \ "(NULL, '%s', %d, %d, '%s', '%s', 0, 0, 1, %d, '%s', NULL)" % \ (title, img_id, type, content, source, user_id, get_current_time()) if excute(insert_article_sql): return json(get_json()) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def update_carouse(): """ 修改轮播图 :arg {"id":1, "type":0, "imgId":1,"status":1,"content":"", "url":"http://www.google.com/","token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"} :arg {"id":1, "type":1, "imgId":1,"status":1,"content":"123", "url":"","token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"} :return: """ carouse_info = request.get_json() id = carouse_info.get("id") url = carouse_info.get("url") type = carouse_info.get("type") img_id = carouse_info.get("imgId") status = carouse_info.get("status") content = carouse_info.get("content") # 参数校验,如果type为0,url不能为空;如果如果为1,content不能为空 if type != None and type == 0: paras = [type, img_id, status, url] else: paras = [type, img_id, status, content] if not _admin_parameters_filter(paras): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新轮播图信息 update_carouse_sql = "update tbl_carouse set type=%d, imgId=%d, status=%d, content='%s', url='%s' where id=%d" % \ (type, img_id, status, content, url, id) if excute(update_carouse_sql): return json(get_json()) return json(get_json(code=-100, msg="添加失败,请检查数据库链接!"))
def update_article(): """ 更新文章 :arg { "id":1, "type":1, "title":"title_test", "source":"1", "status":1, "content":"test_test", "imgId":1,"token": "75wglrvu-uiol-ifza-73c9-d9vu4e5sql0m" } :return: """ article_info = request.get_json() id = article_info.get("id") type = article_info.get("type") title = article_info.get("title") img_id = article_info.get("imgId") source = article_info.get("source") status = article_info.get("status") content = article_info.get("content") # 参数校验 if not _admin_parameters_filter( [id, status, title, type, content, source, img_id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新文章 update_article_sql = "update tbl_article set " \ "title='%s', type=%d, source='%s', status=%d, content='%s', updateDate='%s', imgId='%d'" \ "where id=%d" % (title, type, source, status, content, get_current_time(), img_id, id) if excute(update_article_sql): return json(get_json(msg="更新成功!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def wrapper(*args, **kwargs): token = request.get_json().get("token") if token is not None and token != ""\ and token == session.get("admin_token"): try: return func(*args, **kwargs) except: print(traceback.print_exc()) return json(get_json(code=500, msg="内部错误,请检查参数是否正确!")) return json(get_json(code=-300, msg="权限错误,请先登录!"))
def article_detailes(): """ 查询文章详情和评论 :arg: {"articleId":1} :return: """ article_info = request.get_json() article_id = article_info.get("id") # id为空不允许 if not _parameters_filter([article_id]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # -1:未登录用户 user = session.get("user") if user: user_id = user.get("id") else: user_id = -1 # 首先默认请求此接口为浏览了该文章 try: # 增加浏览数量,如果没有浏览,则增加一条浏览数据,否则修改浏览时间 query_article_sql = "select * from tbl_article_browsing_history " \ "as a where a.userId=%d and a.articleId=%d and a.status=1" % (user_id, article_id) if query(query_article_sql): article_browsing_sql = "update tbl_article_browsing_history set updateDate='%s'" % get_current_time( ) excute(article_browsing_sql) else: article_browsing_sql = "INSERT INTO tbl_article_browsing_history " \ "VALUES (NULL, %d, %d, 1, '%s',NULL)" % (user_id, article_id, get_current_time()) excute(article_browsing_sql) # 查询article阅读总数 query_article_readcount_sql = "select * from tbl_article where id=%d" % article_id read_counts = query(query_article_readcount_sql)[0].get( "readCount") + 1 # 更新readCount总数 update_article_browsing_count = "update tbl_article set readCount=%d, " \ "updateDate='%s' where id=%d" % (read_counts, get_current_time(), article_id) excute(update_article_browsing_count) except Exception as e: print(e) pass # 查询文章和对应的评论 query_article_sql = "select * from tbl_article where id=%s and status=1" % article_id query_comments_sql = "select * from tbl_article_comment where articleId=%s and status=1" % article_id results = { "article": query(query_article_sql), "comments": query(query_comments_sql) } return json(get_json(data=results))
def user_info_page(): """ 进入页面时请求此接口 :params {"token":"pmqkp62j-n5pw-w882-zk3e-qh8722mivo4u"} :return: json """ return json(get_json(data=_get_user_session()))
def user_index(): """ :params {"token":"pmqkp62j-n5pw-w882-zk3e-qh8722mivo4u"} 获取用户个人中心信息,包括历史评论、收藏文章、浏览记录、个人资料 :return: json """ # 历史浏览 user = _get_user_session()["userInfo"] query_comment_his_sql = "select * from tbl_article_comment as " \ "a join tbl_article as b where a.articleId=b.id " \ "and a.userId=%d and a.status=1 and b.status=1 limit 10" % user.get("id") # 收藏文章 query_collect_sql = "select a.* from tbl_article as a JOIN " \ "tbl_article_collect as b on a.id=b.articleId " \ "and b.userId=%s and a.status=1 and b.status=1 " \ "limit 10" % user.get("id") # 浏览记录 query_browsing_his_sql = "select a.* from tbl_article as a JOIN " \ "tbl_article_browsing_history as b on a.id=b.articleId " \ "and b.userId=%d and a.status=1 and b.status=1 limit 10" % user.get("id") # 个人喜欢 query_like_sql = "select a.* from tbl_article as a JOIN " \ "tbl_article_like as b on a.id=b.articleId " \ "and b.userId=%d and a.status = 1 and b.status=1 limit 10" % user.get("id") # 构造响应数据 datas = { "userInfo": _get_user_session().get("userInfo"), "likes": query(query_like_sql), "comments": query(query_comment_his_sql), "collects": query(query_collect_sql), "browsing": query(query_browsing_his_sql) } return json(get_json(data=datas))
def index(): """ 首页接口 :arg :return json """ datas = {} # 返回的数据集,包括用户信息、文章分类和信息、跑马灯、轮播图 # 查询文章信息 articles = [] for type in range(1, 6): title = "article" + str(type) query_article_sql = "select * from tbl_article where type=%s LIMIT 10" % str( type) articles.append({title: query(query_article_sql)}) # 查询跑马灯信息 query_anno_sql = "select * from tbl_announcement where status=1 LIMIT 10" # 查询轮播图信息 query_all_carouses_sql = "select a.*, b.path as imgPath " \ "from tbl_carouse as a JOIN tbl_image_sources as b " \ "where a.imgId=b.id and b.status=1 and a.status=1;" datas = { "articles": articles, "annos": query(query_anno_sql), "carouses": query(query_all_carouses_sql), "userInfo": session.get("user") } return json(get_json(data=datas))
def query_paging_articles(): """ 文章分页查询 :arg {"page":1,"token": "lup5gvda-5vwa-q3yp-kub5-sz69v6qxtgr3"} :return: json 详细格式如下,此接口受前端限制,可能会更改 { "code":200 # 状态码 "msg":"ok", # msg "data":{ # 返回数据对象 {"articles":[ # 文章列表 [文章1],[文章2],[文章3],[文章4], ....[文章10] ]}, { "current_page":1 # 当前页码 }, { "dic_list":[1,4] # 通过这个循环来标注下一页 下下一页的参数 例如 articles?p=2;在这里需要post传json格式{"page":1} }, { "show_index_status":0 # 是否显示首页,0为不显示 }, { "total":3 # 共有几页 } } } """ paging_info = request.get_json() current_page = paging_info.get("page") # 当前页面 show_shouye_status = 0 # 显示首页状态 if current_page == '': current_page = 1 else: current_page = int(current_page) if current_page > 1: show_shouye_status = 1 limit_start = (int(current_page) - 1) * 10 # 查询n-10*n条记录,首页 sql = "select * from tbl_article limit %d,10" % limit_start article_list = query(sql) # 查询总记录和计算总页数 sql = "select * from tbl_article" count = len(query(sql)) # 总记录 total = int(math.ceil(count / 10.0)) # 总页数 dic = _get_page(total, current_page) datas = { "articles": article_list, "current_page": int(current_page), 'total': total, 'show_index_status': show_shouye_status, 'show_range': dic # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range } return json(get_json(data=datas))
def query_paging_users(): """ 用户分页查询 :arg {"page":2,"token": "te4uzdia-gkee-ziiy-5cjg-zz8qji20z7a6"} :return: json 详细格式如下,此接口受前端限制,可能会更改 { "code":200 # 状态码 "msg":"ok", # msg "data":{ # 返回数据对象 {"articles":[ # 文章列表 [用户1],[用户2],[用户3],[用户4], ....[用户10] ]}, { "current_page":1 # 当前页码 }, { "dic_list":[1,4] # 通过这个循环来标注下一页 下下一页的参数 例如 articles?p=2;在这里需要post传json格式{"page":1} }, { "show_index_status":0 # 是否显示首页,0为不显示 }, { "total":3 # 共有几页 } } } """ paging_info = request.get_json() current_page = paging_info.get("page") # 当前页面 show_shouye_status = 0 # 显示首页状态 if current_page == '': current_page = 1 else: current_page = int(current_page) if current_page > 1: show_shouye_status = 1 limit_start = (int(current_page) - 1) * 10 # 查询n-10*n条记录,首页 sql = "select * from tbl_user limit %d,10" % limit_start user_list = query(sql) # 查询总记录和计算总页数 sql = "select * from tbl_user" count = len(query(sql)) # 总记录 total = int(math.ceil(count / 10.0)) # 总页数 dic = _get_page(total, current_page) datas = { "users": user_list, "currentPage": int(current_page), 'total': total, 'showIndexStatus': show_shouye_status, 'showRange': dic # 下一页或下下一页的参数的循环参数(开始,结束) 在python中表示 range } return json(get_json(data=datas))
def admin_index(): """ 管理员首页 :args {"token":"xxx} :return: """ return json(get_json(data=_get_admin_session()))
def user_logout(): """ 用户退出,删除session :arg {"token":"xxxxx"} :return: """ session.pop("user", None) session.pop("user_token", None) return json(get_json())
def get_code_status(): datas = { "code:-100": "操作失败", "code:-200": "参数错误", "code:-300": "权限出错,需要登录", "code:200": "操作成功", "code:500": "内部异常,通常都是参数传错了" } return json(get_json(msg="状态码说明", data=datas))
def query_all_articles(): """ 查询所有文章 :args {"token": "hq1bjvcc-o4ub-dwlv-1uok-lhmixq5lvkl3"} :return: json """ query_articles_sql = "select * from tbl_article order by createDate desc" datas = {"articles": query(query_articles_sql)} return json(get_json(data=datas))
def query_all_users(): """ 查询所有用户 :args {"token": "ol5r2k0p-0fn0-kbyd-1xpe-zq4n6sgk5wa5"} :return: json """ query_users_sql = "select * from tbl_user" datas = {"users": query(query_users_sql)} return json(get_json(data=datas))
def user_login(): """ 用户登录 :arg {"username":"******", "password":"******", "captcha":"123456"} :return json """ user_info = request.get_json() captcha = user_info.get("captcha") username = user_info.get("username") password = user_info.get("password") # 参数校验 if not _parameters_filter([username, password, captcha]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # todo # 修改验证码 if captcha == "123456": query_login_sql = "select * from tbl_user where username='******' and password='******'" % ( username, password) result = query(query_login_sql) if result: if result[0].get("status") == 1: # 生成并插入token user_token = create_token() insert_token_sql = "update tbl_user set token='%s' where id=%d" % ( user_token, result[0]["id"]) excute(insert_token_sql) # 查询IMG并更新Token query_img_sql = "select * from tbl_image_sources where id=%d" % result[ 0].get("imgId") result[0]["img"] = query(query_img_sql)[0].get("path") result[0]["token"] = user_token # 保存用户信息 _set_user_session(result[0]) return json(get_json(data={"token": user_token}, msg="登录成功!")) else: return json(get_json(msg="登录失败, 您已经禁止登陆网站, 请联系管理员处理!")) return json(get_json( code="-100", msg="登录失败,用户名或密码不正确!", ))
def query_all_carouses(): """ :arg {"token": "qzh84z4m-vsl7-ltkq-6xzq-wur2tkts2ppw"} :return: """ query_all_carouses_sql = "select a.*, b.path as imgPath " \ "from tbl_carouse as a JOIN tbl_image_sources as b " \ "where a.imgId=b.id;" datas = {"carouses": query(query_all_carouses_sql)} return json(get_json(data=datas))
def active_article(): """ 激活已删除的文章 :arg {"id":1, "token":"dd0tl9ek-v65c-un69-v450-vdjxweucf0f7"}} :return: """ article_info = request.get_json() id = article_info.get("id") # 参数校验 if not _admin_parameters_filter([id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新文章 update_article_sql = "update tbl_article set status=1 where id=%d" % id if excute(update_article_sql): return json(get_json(msg="激活文章成功!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def delete_anno(): """ 删除公告:软删除 :arg {"id":1,"token": "qzh84z4m-vsl7-ltkq-6xzq-wur2tkts2ppw"} :return: """ anno_info = request.get_json() id = anno_info.get("id") # 参数校验 if not _admin_parameters_filter([id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 构造参数并执行sql delete_anno_sql = "update tbl_announcement set status=0 where id=%d" % id if excute(delete_anno_sql): return json(get_json(msg="删除成功,该公告将不会在首页显示!")) return json(get_json(code=-100, msg="删除失败,请检查数据库链接!"))
def delete_carouse(): """ 删除轮播图 :arg {"id":1, "token": "zwoqgqod-c392-ingy-6cyl-stvk7nadyrpe"} :return: """ carouse_info = request.get_json() id = carouse_info.get("id") # 参数校验 if not _admin_parameters_filter([id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新轮播图 update_carouse_sql = "update tbl_carouse set status=0 where id=%d" % id if excute(update_carouse_sql): return json(get_json()) return json(get_json(code=-100, msg="添加失败,请检查数据库链接!"))
def recover_user(): """ 恢复用户 :arg {"id":1,"token": "2fvblixe-mxqg-weu5-mvqo-48ick796k009"} :return: """ user_info = request.get_json() id = user_info.get("id") # 参数校验 if not _admin_parameters_filter([id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新文章 update_article_sql = "update tbl_user set status=1 where id=%d" % id if excute(update_article_sql): return json(get_json(msg="恢复成功, 该用户可以登陆网站!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def recover_comment(): """ 恢复显示文章的评论 :arg {"id": 1, "token":"3dfvjaj0-81hp-gwzl-wub9-2qsllamg2mou"} :return: json """ comment_info = request.get_json() id = comment_info.get("id") # 参数校验 if not _admin_parameters_filter([id]): return json(get_json(code=-200, msg="操作失败,参数有误!")) # 更新评论记录 update_comment_sql = "update tbl_article_comment set status = 1 where id=%d" % id if excute(update_comment_sql): return json(get_json(msg="评论已设置为显示!")) return json(get_json(code=-100, msg="操作失败,请检查数据库链接!"))
def update_user(): """ 编辑用户信息 :arg { "id":1, "status":1, "sex":"男", "age":22, "email":"*****@*****.**", "wechat":"snake", "remark":"greate full!", "address":"test", "nickname":"snake", "signature":"signature", "cellphone":"15000000000", "education":"education","token": "4cmhr7a8-t0zw-sskr-3e5i-o9sdxv48878p" } :return: json """ user_info = request.get_json() id = user_info.get("id") sex = user_info.get("sex") age = user_info.get("age") email = user_info.get("email") status = user_info.get("status") wechat = user_info.get("wechat") remark = user_info.get("remark") address = user_info.get("address") nickname = user_info.get("nickname") signature = user_info.get("signature") cellphone = user_info.get("cellphone") education = user_info.get("education") updateDate = get_current_time() # 执行用户信息更新 update_user_sql = "update tbl_user set nickname='%s'," \ "sex='%s',age=%d, email='%s', wechat='%s'," \ "remark='%s',address='%s',nickname='%s'," \ "signature='%s',cellphone='%s',education='%s'," \ "updateDate='%s',status=%d where id='%s'" % \ (nickname, sex, age, email, wechat, remark, address, \ nickname, signature, cellphone, education, updateDate, status, id) # 更新成功则重置session并返回最新的用户信息 if excute(update_user_sql): return json(get_json(msg="修改成功!")) return json(get_json(code=-100, msg="修改失败!"))