解决got an unexpected keyword argument ‘pk‘

  File "/usr/local/lib/python2.7/site-packages/djangorestframework-3.3.3-py2.7.egg/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
TypeError: retry() got an unexpected keyword argument 'pk'

具体报错信息如上,确定我代码中的报错位置是 retry() 方法,具体内容如下:

@detail_route(methods=['post'])
def retry(self, request):
    recover_obj = self.get_object()

此方法的url里,带有id参数,提交的内容是空的。但当执行 get_object() 的时候,因取不到pk而报错,所以修改如下:

def retry(self, request, *args, **kwargs):

你可能感兴趣的:(后端,python)