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 xingyu lin)

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

Change History (15)

comment:1 by xingyu lin, 3 weeks ago

Description: modified (diff)

comment:2 by zubair, 3 weeks ago

Please assign this ticket to me, i am working on this.

comment:3 by xingyu lin, 3 weeks ago

Owner: set to zubair
Status: newassigned

comment:4 by zubair, 3 weeks ago

This is the pull request i have created for this ticket.

https://github.com/django/django/pull/20181

in reply to:  4 ; comment:5 by xingyu lin, 3 weeks ago

Got it, thanks for your work.

comment:6 by Youngkwang Yang, 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:7 by zubair, 3 weeks ago

RFC reference added.

in reply to:  5 comment:8 by zubair, 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 Youngkwang Yang, 3 weeks ago

Cc: Youngkwang Yang added

comment:10 by zubair, 3 weeks ago

Please merge this PR.

in reply to:  10 comment:11 by Youngkwang Yang, 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 Jacob Walls, 2 weeks ago

Triage Stage: UnreviewedAccepted
Version: 5.2dev

comment:13 by Jacob Walls, 2 weeks ago

Has patch: set
Patch needs improvement: set

comment:14 by Jacob Walls, 2 weeks ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:15 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

Resolution: fixed
Status: assignedclosed

In ff843bc:

Fixed #36734 -- Clarified the behavior of View.http_method_not_allowed.

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