Django Rest Framework APIView no delete and put allowed -
i working on tutorial on website of django rest framework. when make put or delete call server methods particular not allowed. view:
class snippetdetailview(apiview): def put(self, request, pk, format=none): snippet = self.get_object(pk) serializer = snippetserializer(snippet, data=request.data) if serializer.is_valid(): serializer.save() return response(serializer.data) return response(serializer.errors, status=status.http_400_bad_request) def delete(self, request, pk, format=none): snippet = self.get_object(pk) snippet.delete() return response(status=status.http_204_no_content)
i used following urls.py
urlpatterns = [ url(r'^snippets/', snippetlistview.as_view()), url(r'^snippets/(?p<pk>[0-9]+)/$', snippetdetailview.as_view()), ]
my response header shows following:
allow → get, post, head, options
i haven't set restrictions whatsoever. did miss doesn't allow put , delete methods?
thanks
for still struggling issue. after hours of moving , forth found solution. issues url. old urlpatterns
urlpatterns = [ url(r'^snippets/', snippetlistview.as_view()), url(r'^snippets/(?p<pk>[0-9]+)/$', snippetdetailview.as_view()), ]
working urlpatterns:
urlpatterns = [ url(r'^snippets/$', snippetlistview.as_view()), url(r'^snippets/(?p<pk>[0-9]+)$', snippetdetailview.as_view()), ]
the difference minute issue related trailing slash in old version used trigger snippetdetailview.
hope helps!
Comments
Post a Comment