Opened 8 hours ago
Closed 7 hours ago
#36209 closed New feature (duplicate)
Add HttpResponse subclasses for No Content and Created
Reported by: | Michiel Beijen | Owned by: | |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | HttpResponse REST 201 204 |
Cc: | Michiel Beijen | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django has HttpResponse subclasses for many status codes. Although you can use the generic HttpResponse and provide it with a status code, the subclasses provide for more readable code: it's more clear to write HttpResponseRedirect() or HttpResponsePermanentRedirect() than to use HttpResponse with a 301 or 302 status code, because that requires you to 'know' which status code is which.
However for the RESTful HTTP response codes 201 Created and 204 No Content there are no HttpResponse subclasses. It would be helpful to people writing RESTful HTTP APIs to have HttpResponse subclasses for these codes.
This patch adds HttpResponseCreated and HttpResponseNoContent subclasses. I've targeted Django 6 because 5.2 is closed for new features.
Change History (1)
comment:1 by , 7 hours ago
Keywords: | 201 204 added |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Thanks for the ticket.
For self-documenting/readable status codes, the advice is to use the
HTTPStatus
enum from python.Duplicate of #3362
Also discussed recently on forum for JSONResponse.