【发布时间】:2022-06-26 16:05:23
【问题描述】:
请帮我解决这个问题。提前致谢。
在这里,如果电话号码存在,则表明它存在,否则会向我抛出错误,例如:
`/validate_phone/ 处的断言错误
请求参数必须是 django.http.HttpRequest 的实例,而不是 builtins.str。 `
@permission_classes((permissions.AllowAny,))
class ValidatePhoneSendOTP(APIView):
def post(self, request, *args, **kwargs):
phone_number = request.data.get('phone')
if phone_number:
phone = str(phone_number)
user = UserModel.objects.filter(phone__iexact=phone)
if user.exists():
return Response({
'status': False,
'detail': 'Phone number already exists'
})
else:
key = send_otp(phone)
if key:
old = PhoneOTP.objects.filter(phone__iexact=phone)
if old.exists():
old = old.first()
count = old.count()
if count > 10:
return Response({
'status': False,
'detail': "Sending otp error. Limit exceeded. Please contact customer support."
})
old.count = count + 1
old.save()
print("count increase", count)
return Response({
'status': True,
'detail': "OTP sent successfully."
})
else:
PhoneOTP.objects.create(
phone=phone,
otp=key,
)
return Response({
'status': True,
'detail': 'OTP sent successfully'
})
【问题讨论】:
-
总是发布完整的错误回溯!
-
好的,我知道了
标签: python django django-rest-framework django-views