I have added tastypie to my Django project with a Mongodb backend. When I query /api/myresource
I get this error:
{"error_message": "get_resource_uri() takes exactly 2 arguments (1 given)",
"traceback": "Traceback (most recent call last):\n\n
File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 195,
in wrapper\n response = callback(request, *args, **kwargs)
File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 426,
in dispatch_list\n return self.dispatch('list', request, **kwargs)
File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 458,
in dispatch\n response = method(request, **kwargs)
File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\",
line 1269, in get_list
paginator = self._meta.paginator_class(request.GET,
sorted_objects, resource_uri=self.get_resource_uri(), limit=self._meta.limit, max_limit=self._meta.max_limit, collection_name=self._meta.collection_name)
TypeError: get_resource_uri() takes exactly 2 arguments (1 given)\n"}
I encountered the same error when I upgraded my app from django 1.4 to 1.7 and upgraded django-tastypie too. One of my resources had it's own definition of get_resource_uri: get_resource_uri(self, bundle_or_obj)
.
In newer versions of django-tastypie the second argument is now defaulted:
def get_resource_uri(self, bundle_or_obj=None, url_name='api_dispatch_list'):
So I changed my method signature to match the newer signature and all was well.
It turns out I no longer needed to override the get_resource_uri() for my use case so I could just delete it.