首页 > 解决方案 > 'Request' 对象在获取 api url 时没有属性 'get' 错误

问题描述

在此,当我到达 validat_phone URL 并在 URL 中发布 phone_number 时,它返回错误 'Request' object has no attribute 'get',我不知道如何修复该错误。有没有办法修复错误?

这是我的观点.py

class ValidatePhoneSendOTP(APIView):

    def post(self, request, *args, **kwargs):
        phone_number = request.data.get('phone', False)

        if phone_number:
            phone = str(phone_number)
            user = User.objects.filter(phone__iexact = phone)
            if user.exists():
                return Response({
                    'status' : False,
                    'status' : 'Phone number is already exists.'
                    })
            else:
                key = send_otp(phone)
                if key:

                    PhoneOTP.objects.create(
                        phone = phone,
                        otp = key,
                    )
                    link = f'My--api-url - {phone}+ {key}'
                    test = request.get(link)
                    return test;

                    return Response({
                        'status' : True,
                        'detail' : 'OTP sent successfully.'
                    })
                else:
                    return Response({
                        'status' : False,
                        'detail' : 'Sending otp error.'
                        })

                
        else:
            return Response({
                'status' : False,
                'detail' : 'Phone number is not given in post request.'
                })


def send_otp(phone):
    if phone:
        key = random.randint(999,9999)
        print(key)
        return key
    else:
        return False

标签: pythonpython-3.xdjangoviewdjango-rest-framework

解决方案


推荐阅读