我需要访问我的资源脱水中的HttpRequest对象方法。
在文档中,它显示了这个bundle。Request是一个有效的属性(它是在resources.html页面中)。当我尝试将它添加到代码中时,我得到一个错误声明Bundle' object '没有属性'request'。到底发生了什么事?
Bundle对象有request属性。
class Bundle(object):
"""
A small container for instances and converted data for the
``dehydrate/hydrate`` cycle.
Necessary because the ``dehydrate/hydrate`` cycle needs to access data at
different points.
"""
def __init__(self, obj=None, data=None, request=None):
self.obj = obj
self.data = data or {}
self.request = request or HttpRequest()
无论如何,您可以覆盖调用堆栈中高于dehydrate
的Resource方法。
你能给我看看代码吗?
我刚刚遇到了同样的问题,但在这里找到了正确的答案:http://groups.google.com/group/django-tastypie/tree/browse_frm/thread/801f44af3f2dbe7b/a36f303380eacf96
看起来django-tasty-pie版本0.9.9没有这个属性,但是版本0.9.10有!
所以如果你使用buildout,查看buildout.cfg在版本:搜索django-tastypie = 0.9.9
删除这个,看看你的安装选择或替换为:
django-tastypie = 0.9.10
我仍然有这个问题,所以打开了一个新的链接,见:
django- tastype: Cannot access bundle。请求脱水(self,bundle)
在上面的问题中我发现,使用0.9.10版本是不够的,1.0.0版本测试版应该做这三件事。