Code in Python Django:
if len(error) < 1:
return Response(status=HTTP_200_OK)
else:
return Response({"data":error}status=HTTP_400_BAD_REQUEST)
code in javascript
if(response.status===200){
alert("ok")
}else if(response.status===400){
alert("not ok")
}
It returns the code when it is 200 ok, but returning nothing when it is 400 bad request. In fact, nothing seems replying message except 200_ok code. Is there any solution for that?
Try with:
return Response(status=HTTP_400_BAD_REQUEST, data=error)
Docs: https://www.django-rest-framework.org/tutorial/2-requests-and-responses/#response-objects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With