Hed*_*ide 4 python django tastypie
对,我很难理解这一个,
在我的本地环境中,我为django User对象集成了用户名查找:
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"),
]
Run Code Online (Sandbox Code Playgroud)
在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
Run Code Online (Sandbox Code Playgroud)
游览:
/ API/V1 /用户/富/?格式= JSON
这打印:
1, {'username': foo'}
2, [<User: foo>]
1, {'id': 1}
2, [<User: foo>]
Run Code Online (Sandbox Code Playgroud)
并返回正确的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
Run Code Online (Sandbox Code Playgroud)
我也得到这个堆栈跟踪:
{
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).
"
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
| 归档时间: |
|
| 查看次数: |
3993 次 |
| 最近记录: |