[Django]-How to delete an object using Django Rest Framework

46👍

You’re being redundant. The HTTP method is already DELETE, so there’s no /events/delete in the url. Try this:

curl -X DELETE "http://127.0.0.1:8000/events/1/"

By default, DRF’s router creates detailed urls at /event/<pk> and you GET, PUT, POST and DELETE them to retrieve, update, create and delete respectively.

2👍

As mentioned by Kevin Stone, the pattern you’re using isn’t advisable, but if you want to use it, you’ll need to fix the typo in your urls for the events/delete/ mapping.

 # delete event
 url(r'^delete$/(?P<pk>\d+)',
     views.EventDetail.as_view(), name='delete_event'),

should be:

 # delete event
 url(r'^delete/(?P<pk>\d+)',
     views.EventDetail.as_view(), name='delete_event'),

Leave a comment