在我的装饰器中:
def check_user_identity(function):
def wrap(request, *args, **kwargs):
response_check_user = mock_response.check_user_identity(requested_data=request.data['msisdn'])
if response_check_user['status'] == SUCCESS_CODE:
return function(request, *args, **kwargs)
return Response(data=INVALID_USER, status=status.HTTP_400_BAD_REQUEST)
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
在我看来: 在这里,request参数具有我请求继续执行的值。首先调用装饰器。我想从装饰器访问我的请求数据。
class VerifyWallet(APIView):
@check_user_identity
def post(self, request):
logger.debug(msg=request.data)
serializer = VerifyWalletSerializer(data=request.data)
if not serializer.is_valid():
logger.error(msg=serializer.errors)
return Response(data=serializer.errors, status=status.HTTP_400_BAD_REQUEST)
return Response(data='success', status=status.HTTP_200_OK)
答案 0 :(得分:0)
经过我所有的搜索,我找到了答案。值在 args[0] 中。