I have been trying and searching alot but no one had this problem apparently. So the problem is that i am trying to send an axios request to delete with the correct api ur and key. But DRF Model.ViewSet does not find the function with appropriate PK.
Backend This is my view.py file:
class GigList(ViewSet):
def destroy(self, request, pk=None):
print(pk)
Gig.objects.filter(user=request.user, id=request.id).delete()
return Response
urls.py:
router = DefaultRouter()
router.register('api', views.GigList, basename='user')
Frontend This is the js file where axios executes:
async deleteGig(id) {
const response = await api.delete(`api/destroy/${id}` `/`,TokenService.getLocalAccessTokenHeader() );
return response
}
Django outputs:
Not Found: /api/destroy/17/
[09/Jan/2022 23:44:46] "DELETE /api/destroy/17/ HTTP/1.1" 404 8064
If anyone has an hint or solution to this, i would be grateful, thanks guys
CodePudding user response:
As shown in the docs, the destroy endpoint is similar to the retrieve/update/partial_update endpoints, with the main difference being the http method. So all of them use api/17, and the viewset knows which action to use based on the http method.
So change:
await api.delete(`api/destroy/${id}` `/`,
To just:
await api.delete(`api/${id}` `/`,
