DEV Community

Gahyun Son
Gahyun Son

Posted on

Understanding Response Status Codes in Django REST Framework

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)
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

You must explicitly specify the status parameter name.

return Response(status=status.HTTP_204_NO_CONTENT)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay