“detail”: “method \delete\ not allowed” django

as I wrote in the comment looks like you don’t need a ViewSet because you are handling just operations on a single item. In general you can restrict the operations available for Views or ViewSet using proper mixins.

I suggest two possible approaches

Use Generic View

class UpdateDeletePostView(
        UpdateModelMixin,
        DeleteModelMixin,
        GenericAPIView):
    .....

and

urlpatterns = [
    path('post/<int:pk>', UpdateDeletePostView.as_view()),
    ...
]

Use ViewSet and Router

class UpdateDeletePostViewSet(
        UpdateModelMixin,
        DeleteModelMixin,
        GenericViewset):
    .....
router = SimpleRouter()
router.register('feed', UpdateDeletePostViewSet)

urlpatterns = [
    path('', include(router.urls)),
    ...
]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top