gpt4 book ai didi

python - 未找到 Tastypie : Invalid resource lookup data provided (mismatched type)

转载 作者:太空狗 更新时间:2023-10-30 01:51:56 25 4
gpt4 key购买 nike

对,我很难理解这个,

在我的本地环境中,我为 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/users/foo/?format=json

这打印:

1,  {'username': foo'}
2, [<User: foo>]
1, {'id': 1}
2, [<User: foo>]

并返回正确的 JSON 对象。

然而,在我的远程(开发)服务器上我有完全相同的设置(我仔细检查了所有文件),唯一的区别似乎是它运行的是 tastypie python 2.7 egg 而不是 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).
"

}

有什么想法吗?

最佳答案

对,答案:

将 prepend_urls 更改为(将被弃用)override_urls 修复了这个错误,我会在 github 上报告这个,似乎是一个 2.7 egg 问题

关于python - 未找到 Tastypie : Invalid resource lookup data provided (mismatched type),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11684659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com