1 统一接口的返回方式,即便视图函数执行出错 2 使用方式 -写一个函数 def common_exception_handler(exc, context): response = exception_handler(exc, context) if response is None: response = Response({'code':999,'detail': '未知错误'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return response -在setting中配置 REST_FRAMEWORK = { 'EXCEPTION_HANDLER':'app01.utils.common_exception_handler' }