Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Description
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',}