我正在尝试使用此处的示例:http: //django-tastypie.readthedocs.org/en/latest/cookbook.html#nested-resources
出于某种原因,我得到:
cached_obj_get() 正好需要 2 个参数(给定 1 个)
即使我清楚地用 2 个参数调用它(就像前面提到的例子一样。这是我的代码:
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/feed%s$" % (self._meta.resource_name, trailing_slash()), self.wrap_view('get_feed'), name="api_get_feed"),
]
def get_feed(self, request, **kwargs):
try:
obj = self.cached_obj_get(request=request, **self.remove_api_resource_names(kwargs))
except ObjectDoesNotExist:
return HttpGone()
except MultipleObjectsReturned:
return HttpMultipleChoices("More than one resource is found at this URI.")
feed_resource = FeedItemResource()
return feed_resource.get_list(request, p_id=obj.id)