Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mark extra actions which corresponds to the same URL #4920

Closed
Assignees
rpkilby
@theosotr

Description

@theosotr

Imagine that I have two extra actions that corresponds to the same url (e.g. likecreate() withlist() which corresponds to the name url i.e.^{prefix}/{name}/ but with different HTTP methods).

fromrest_frameworkimportviewsetsfromrest_framework.decoratorsimportdetail_routeclassMyViewSet(viewsets.ViewSet):@detail_route(methods=['get'],url_path='foo',url_name='foo_get')deffoo_get(self,request,pk=None):pass@detail_route(methods=['head'],url_path='foo',url_name='foo_head')deffoo_head(self,request,pk=None):pass

I want to use theDefaultRouter class to construct url patterns rather than creating urls on my own like follows:

extra_actions=MyView.as_view({'head':'foo_head','get':'foo_get'})

The problem here is that the_get_dynamic_routes() method ofSimpleRouter class create a namedtuple (Route) for every extra action, and therefore only the first extra action is taken into account. So, the fist call succeeds whereas the second call returns HTTP 405 METHOD_NOT_ALLOWED.

# This call woks.curl -X get http:localhost:8000/api/products/1/foo/# This returns 405.curl -X head http:localhost:8000/api/products/1/foo/

All in all, I would expect that oneRoute should be created by the_get_dynamic_routes() with the following mapping (Remeber that I want these extra actions to correspond to thesame url!):

mapping= {'get':'foo_get','head':'foo_head',}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp