#36734: Clarify documentation about default implementation of
`http_method_not_allowed`
-------------------------------------+-------------------------------------
Reporter: xingyu0618 | Type:
| Cleanup/optimization
Status: new | Component:
| Documentation
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
https://docs.djangoproject.com/en/5.2/ref/class-based-
views/base/#django.views.generic.base.View.http_method_not_allowed
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):
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')
}}}
--
Ticket URL: <
https://code.djangoproject.com/ticket/36734>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.