#36734: Clarify documentation about default implementation of
`http_method_not_allowed`
-------------------------------------+-------------------------------------
Reporter: xingyu lin | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by xingyu lin:
Old description:
> 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')
> }}}
New description:
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, 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')
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36734#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019a8826ac05-0189c4d0-67c0-4d89-b059-ebee0c00ba36-000000%40eu-central-1.amazonses.com.