[Django] #36209: Add HttpResponse subclasses for No Content and Created

6 views
Skip to first unread message

Django

unread,
Feb 22, 2025, 9:32:09 AM (3 days ago) Feb 22
to django-...@googlegroups.com
#36209: Add HttpResponse subclasses for No Content and Created
-------------------------------------+-------------------------------------
Reporter: Michiel Beijen | Type: New
| feature
Status: new | Component: HTTP
| handling
Version: dev | Severity: Normal
Keywords: HttpResponse REST | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36209>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2025, 11:01:56 AM (3 days ago) Feb 22
to django-...@googlegroups.com
#36209: Add HttpResponse subclasses for No Content and Created
-------------------------------------+-------------------------------------
Reporter: Michiel Beijen | Owner: (none)
Type: New feature | Status: closed
Component: HTTP handling | Version: dev
Severity: Normal | Resolution: duplicate
Keywords: HttpResponse REST | Triage Stage:
201 204 | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* keywords: HttpResponse REST => HttpResponse REST 201 204
* resolution: => duplicate
* status: new => closed

Comment:

Thanks for the ticket.

> 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.

For self-documenting/readable status codes, the advice is to use the
`HTTPStatus` [https://docs.python.org/3/library/http.html#http.HTTPStatus
enum] from python.

Duplicate of #3362

Also [https://forum.djangoproject.com/t/proposal-custom-jsonresponse-
status-classes/36426/7 discussed] recently on forum for JSONResponse.
--
Ticket URL: <https://code.djangoproject.com/ticket/36209#comment:1>
Reply all
Reply to author
Forward
0 new messages