1👍
✅
DRF has an inbuilt mechanism to help with this but on request method support is GET. Here’s the reference from the documentation: http://www.django-rest-framework.org/api-guide/routers/#simplerouter
The work around could be to override the post
function in your view and take the argument add
as input to it. For example,
urls.py
url(r'users/(?P<id>[\d]+)/(?P<method>add)/$, UserListView.as_view)
views.py
def post(self,request, *args, **kwargs):
method = kwargs.get('method') # value should be "add"
# check if the method exist in the view
# if yes, call it
method_obj = getattr(self, method)
if method_obj:
data = request.POST #{'id':'joe}
id = data.get('id')
method_obj(id=id)
def add(self, id):
#do soemthing
Update:
POST data i.e. {"id":"joe"}
is available in the request
and can be accessed via request.POST
.
Source:stackexchange.com