Understanding Response Status Codes in Django REST Framework
Gahyun Son
Posted on October 24, 2024
When returning a response with data, you can omit the status parameter name if you're using HTTP_200_OK.
return Response(serializer.data, status.HTTP_200_OK)
However, when returning a response without data, simply passing the status code without the parameter name won't work as expected.
return Response(status.HTTP_204_NO_CONTENT)
You must explicitly specify the status parameter name.
return Response(status=status.HTTP_204_NO_CONTENT)
💖 💪 🙅 🚩
Gahyun Son
Posted on October 24, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.