【问题标题】:Tastypie NotFound: Invalid resource lookup data provided (mismatched type)Tastypie NotFound:提供的资源查找数据无效(类型不匹配)
【发布时间】:2012-07-27 09:01:19
【问题描述】:

是的,我很难理解这一点,

在我的本地环境中,我已经集成了 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"),
        ]

在tastepie的源代码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 对象。

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

}

有什么想法吗?

【问题讨论】:

    标签: python django tastypie


    【解决方案1】:

    对,答案是:

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

    【讨论】:

    • 看起来很疯狂,这仍然没有在美味派的文档中更新。
    【解决方案2】:

    【讨论】:

      【解决方案3】:

      prepend_urls 适用于 0.9.12a 版的美味派。

      在tastepie v0.9.11 中,您应该改用override_urls。 (根据this。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多