Opened 5 hours ago

Last modified 5 hours ago

#36734 new Cleanup/optimization

Clarify documentation about default implementation of `http_method_not_allowed` — at Initial Version

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

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')

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top