Пример #1
0
 def get(self, user_id):
     '''
     :param user_id:是一个字符串,需要转换为int格式
     :return:如果没有查找到指定的数据,则返回404
     '''
     try:
         #查询指定的id返回的数据
         user = UserModel.get(int(user_id))
     except KeyError:
         #返回哟长数据 异常信息不要写中文
         resp = {"status": False, "msg": "select failure"}
         info = json_encode(resp)
         info = """
         <!DOCTYPE html>
             <html lang="en">
             <head>
                 <meta charset="UTF-8">
                 <title>Title</title>
             </head>
             <body>
             {}
             </body>
         </html>
         """.format(info)
         self.write(info)
         return self.set_status(404)
     #返回正常数据
     self.write(json_encode(user))
Пример #2
0
def user_update(email):
    error = None
    actions = []
    data = {}

    try:
        data = UserSchema().load(request.json)
    except ValidationError as err:
        error = err

    for key, value in data.items():
        actions.append(getattr(UserModel, key).set(value))
    user = UserModel.get(email)
    user.update(actions=actions)

    return {
        "status": "error" if error else "success",
        "error": error,
        "data": UserSchema().dump(user)
    }
Пример #3
0
def user_delete(email):
    user = UserModel.get(email)
    user.delete()
    return {"status": "success", "message": "User deleted successfully!"}