-1

Using Django==2.2.11, djangorestframework==3.8.1

Thank you for reading!

The urls I am using that have the collision:

urlpatterns = [
    . . . 
    url(
        r'^some-path$',
        views.MyViewSet.as_view({'get': 'list'})
    ),
    url(
        r'^some-path$',
        views.MyViewSet.as_view({'post': 'create'}),
    ),
    ...
]

I am using postman to test each path, and it seems like there is a collision between these two urls.

Using this url with a GET, would work:

http://my_domain.com:8000/some-path

But POST with same url (and with a valid payload) would throw error:

WARNING 2020-03-28 19:13:57,288 "POST /some-path HTTP/1.1" 405 41

And response:

{"detail": "Method \"POST\" not allowed."}

I urls are swapped in order, then the POST would work, and GET would throw a similar error.

I looked at this post: 405 POST method not allowed

I would gladly add the view code - but I am pretty sure the issue is with the urls, since they each work when swapped order. Will add it upon request.

Thank you!

EDIT: I confused the urls- added the retrieve instead of list sorry!

camelBack
  • 580
  • 1
  • 6
  • 18
  • I don't understand how URL collision will happen in your case since `POST /some-path` and `GET /some-path/` are different. (FYI: I tried to reproduce the issue, but I couldn't) – JPG Mar 29 '20 at 02:59
  • @ArakkalAbu I mistakenly posted the wrong url for the GET - apologies I fixed the question above, PTAL – camelBack Mar 29 '20 at 02:59

1 Answers1

1

If you are pointing to same end-point, ie /some-path, you should add your extra actions as,

urlpatterns = [
    url(r'^some-path$', MusicianViewset.as_view({'post': 'create', 'get': 'list'})),
]
JPG
  • 56,458
  • 6
  • 55
  • 118