當前位置: 首頁>>代碼示例>>Python>>正文


Python UserModel.find_by_id方法代碼示例

本文整理匯總了Python中models.user.UserModel.find_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python UserModel.find_by_id方法的具體用法?Python UserModel.find_by_id怎麽用?Python UserModel.find_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.user.UserModel的用法示例。


在下文中一共展示了UserModel.find_by_id方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_crud

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import find_by_id [as 別名]
    def test_crud(self):
        with self.app_context():
            user = UserModel('test', 'abcd')

            self.assertIsNone(UserModel.find_by_username('test'), "Found an user with name 'test' before save_to_db")
            self.assertIsNone(UserModel.find_by_id(1), "Found an user with id '1' before save_to_db")

            user.save_to_db()

            self.assertIsNotNone(UserModel.find_by_username('test'),
                                 "Did not find an user with name 'test' after save_to_db")
            self.assertIsNotNone(UserModel.find_by_id(1), "Did not find an user with id '1' after save_to_db")
開發者ID:senarclens,項目名稱:testing-python-apps,代碼行數:14,代碼來源:user_test.py

示例2: identity

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import find_by_id [as 別名]
def identity(payload):
    """
    Function that gets called when user has already authenticated, and Flask-JWT  verified their authorizations header
    is correct.
    :param payload: A dictionary with 'identity' , key, which is the user id.
    :return: A UserModel object.
    """

    user_id = payload['identity']
    return UserModel.find_by_id(user_id)
開發者ID:b9007,項目名稱:Python,代碼行數:12,代碼來源:security.py

示例3: delete

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import find_by_id [as 別名]
 def delete(cls, user_id: int):
     user = UserModel.find_by_id(user_id)
     if not user:
         return {'message': 'User Not Found'}, 404
     user.delete_from_db()
     return {'message': 'User deleted.'}, 200
開發者ID:kpgdsc,項目名稱:rest-api-sections,代碼行數:8,代碼來源:user.py

示例4: get

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import find_by_id [as 別名]
 def get(cls, user_id: int):
     user = UserModel.find_by_id(user_id)
     if not user:
         return {'message': 'User Not Found'}, 404
     return user.json(), 200
開發者ID:kpgdsc,項目名稱:rest-api-sections,代碼行數:7,代碼來源:user.py

示例5: identity

# 需要導入模塊: from models.user import UserModel [as 別名]
# 或者: from models.user.UserModel import find_by_id [as 別名]
def identity(payload):
    user_id = payload['identity']
    return UserModel.find_by_id(user_id)
開發者ID:harrysoer,項目名稱:flask-api,代碼行數:5,代碼來源:security.py


注:本文中的models.user.UserModel.find_by_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。