Opened 3 weeks ago
Closed 2 weeks ago
#36734 closed Cleanup/optimization (fixed)
Clarify documentation about default implementation of `http_method_not_allowed`
| Reported by: | xingyu lin | Owned by: | zubair |
|---|---|---|---|
| Component: | Documentation | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Youngkwang Yang | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The quoted description:
If the view was called with an HTTP method it doesn’t support, this method is called instead. The default implementation returns HttpResponseNotAllowed with a list of allowed methods in plain text.
The original description would make you assume that it returns HttpResponseNotAllowed(http 405) with content containing a list of allowed methods in plain text.
But in fact, the default implementation returns HttpResponseNotAllowed with headers[Allow] containing a list of allowed methods in plain text, not in the content.
class TestView(View):
def get(self, req):
return HttpResponse('ok')
class Test(TestCase):
def test(self):
resp = self.client.post('/test')
# The content is empty.
# Allowed methods are in headers['Allow'].
self.assertEqual(resp.content, b'')
self.assertEqual(resp.headers['Allow'], 'GET, HEAD, OPTIONS')
Change History (15)
comment:1 by , 3 weeks ago
| Description: | modified (diff) |
|---|
comment:2 by , 3 weeks ago
comment:3 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:6 by , 3 weeks ago
I think it would be good to add an RFC reference.
like:
The default implementation returns ``HttpResponseNotAllowed`` with the list of allowed methods
in the ``Allow`` header. The response body is empty, as required by :rfc:`RFC 7231 <7231#section-6.5.5>`.
comment:8 by , 3 weeks ago
Replying to xingyu lin:
Got it, thanks for your work.
You are most welcome.
And thank you for your kind and quick response.
comment:9 by , 3 weeks ago
| Cc: | added |
|---|
comment:11 by , 3 weeks ago
Replying to zubair:
Please merge this PR.
Just a note: this ticket is still in "Unreviewed" stage. A Django core developer
will need to triage and accept it before merging. Let's wait for their review.
See the contribution process here: https://docs.djangoproject.com/en/dev/internals/contributing/triaging-tickets/#triage-stages
comment:12 by , 2 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|---|
| Version: | 5.2 → dev |
comment:13 by , 2 weeks ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | set |
comment:14 by , 2 weeks ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Please assign this ticket to me, i am working on this.