I am trying to verify otp. The table in db for otp contains email and otp_no. I am getting the expected outcome if the otp provided by the user is correct but get "AttributeError: 'NoneType' object has no attribute 'email'" if the otp is wrong.
Following is the code:
@api_view(['POST'])
def verifyOtp(request):
email = request.data.get('email')
otp_no = request.data.get('otp_no')
res = dict()
if email!= None and otp_no!= None:
result = Otp.objects.filter(email=email, otp_no = otp_no).first()
if len(result.email)> 0:
res['isOtpVerified'] = True if otp_no == result.otp_no else False
return JsonResponse(res)
else:
res['emailExist'] = False
return JsonResponse(res)
what am I missing in the code?