Opened 94 minutes ago
Last modified 54 minutes ago
#36734 new Cleanup/optimization
Clarify documentation about default implementation of `http_method_not_allowed`
| Reported by: | xingyu lin | Owned by: | |
|---|---|---|---|
| Component: | Documentation | Version: | 5.2 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | 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')
Note:
See TracTickets
for help on using tickets.