python - '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
解决方案
推荐阅读
- java - 使用 Java 读取存储在 WildFly 的 Elytron 凭证存储中的密码?
- wpf - MahApps MetroWindow Topmost 属性绑定问题
- batch-file - 计算批处理文件中的上一个日期是无聊的
- javascript - 如何在弹出窗口而不是内部 html 中显示消息
- java - 为什么我们需要动态绑定(Java)?
- python - 在熊猫中将列中的所有值从最大值反转为最小值,反之亦然
- python - 如何在python中同时为不同的值运行一个函数?
- uber-api - 无法确定集成所需的范围
- vulkan - 创建逻辑设备时出现访问冲突
- react-native - 如何动态更改本机 BottomTabNavigator 颜色