右键我有一个很难理解这一条,Tastypie NOTFOUND:对于Django的用户对象的无效资源查找资料提供(不匹配的类型)
在我的本地环境我已经将用户名查询:
class UserResource(ModelResource):
class Meta:
queryset = User.objects.all()
excludes = ['password', 'email', 'is_staff', 'is_active', 'is_superuser']
resource_name = 'users'
include_resource_uri = False
filtering = {
'username': ALL
}
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]
在tastypie的来源,resources.py我在行1800+
def obj_get(self, request=None, **kwargs):
"""
A ORM-specific implementation of ``obj_get``.
Takes optional ``kwargs``, which are used to narrow the query to find
the instance.
"""
try:
print "1, ", kwargs
base_object_list = self.get_object_list(request).filter(**kwargs)
print "2, ", base_object_list
# etcetera
访问增加了两个打印语句:
?/API/V1 /用户/富/格式= JSON
此打印:
1, {'username': foo'}
2, [<User: foo>]
1, {'id': 1}
2, [<User: foo>]
并返回正确的JSON对象。但是,在我的远程(dev)服务器上我有完全相同的设置(我双重检查了所有文件),唯一的区别是似乎是,它运行的是tastypie python 2.7蛋而不是2.6,无论如何,我得到这个打印:
1, {'pk': u'foo'}
[27/Jul/2012 10:48:37] "GET /api/v1/users/foo/?format=json HTTP/1.0" 404 1219
我也得到这个堆栈跟踪:
{
error_message: "Invalid resource lookup data provided (mismatched type).",
traceback: "Traceback (most recent call last):
File "...path.../resources.py", line 192, in wrapper
response = callback(request, *args, **kwargs)
File "...path.../resources.py", line 406, in dispatch_detail
return self.dispatch('detail', request, **kwargs)
File "...path.../resources.py", line 427, in dispatch
response = method(request, **kwargs)
File "...path.../resources.py", line 1051, in get_detail
obj = self.cached_obj_get(request=request, **self.remove_api_resource_names(kwargs))
File "...path.../resources.py", line 921, in cached_obj_get
bundle = self.obj_get(request=request, **kwargs)
File "/...path.../resources.py", line 1765, in obj_get
raise NotFound("Invalid resource lookup data provided (mismatched type).")
NotFound: Invalid resource lookup data provided (mismatched type).
"
}
有什么想法?
太疯狂了,这仍然没有在该文档的tastypie更新。 – teewuane 2014-09-16 03:52:16