【Python】后台开发返回方法和状态码类的实现

avatar
作者
筋斗云
阅读量:0

Python 后台开发中,获取返回的类方法,以及状态码类的实现

代码备份

Code - response.py

""" Response class for quick generate response """ from loguru_logger import get_logger  logger = get_logger(__name__)  class Response():     @staticmethod     def get_response(code, message, data=None):         return {             "code": code,             "message": message,             "data": data if data is not None else {}         } 

Code - status_code.py

class StatusCode:     # Success     SUCCESS = 0  # Request successful, business processing successful      # Client errors     ERROR_BAD_REQUEST = 400  # Invalid request     ERROR_UNAUTHORIZED = 401  # Unauthorized     ERROR_FORBIDDEN = 403  # Forbidden     ERROR_NOT_FOUND = 404  # Resource not found     ERROR_METHOD_NOT_ALLOWED = 405  # Method not allowed     ERROR_CONFLICT = 409  # Resource conflict     ERROR_UNPROCESSABLE_ENTITY = 422  # Unprocessable entity (e.g., validation error)      # Server errors     ERROR_INTERNAL_SERVER = 500  # Internal server error     ERROR_NOT_IMPLEMENTED = 501  # Not implemented     ERROR_SERVICE_UNAVAILABLE = 503  # Service unavailable      # Business errors     ERROR_VALIDATION_FAILED = 1001  # Validation failed     ERROR_USER_NOT_FOUND = 1002  # User not found     ERROR_INSUFFICIENT_RESOURCE = 1003  # Insufficient resources     ERROR_PERMISSION_DENIED = 1004  # Permission denied     ERROR_OPERATION_FAILED = 1005  # Operation failed      # Database errors     DB_CONNECTION_FAILED = 2001  # Database connection failed     DB_QUERY_FAILED = 2002  # Database query failed     DB_INSERT_FAILED = 2003  # Database insert failed     DB_UPDATE_FAILED = 2004  # Database update failed     DB_DELETE_FAILED = 2005  # Database delete failed     DB_TRANSACTION_FAILED = 2006  # Database transaction failed     DB_RECORD_NOT_FOUND = 2007  # Database record not found     DB_NO_CHANGE = 2008  # Data no change 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!