【发布时间】:2011-11-15 10:05:31
【问题描述】:
我需要访问我的资源脱水中的 HttpRequest 对象 方法。
在文档中,它表明 bundle.request 是一个有效的属性(它是 在 resources.html 页面中)。当我尝试将其添加到我的代码中时,我得到一个 错误声称 Bundle' 对象没有属性 'request'。 什么给了?
【问题讨论】:
标签: django api resources tastypie
我需要访问我的资源脱水中的 HttpRequest 对象 方法。
在文档中,它表明 bundle.request 是一个有效的属性(它是 在 resources.html 页面中)。当我尝试将其添加到我的代码中时,我得到一个 错误声称 Bundle' 对象没有属性 'request'。 什么给了?
【问题讨论】:
标签: django api resources tastypie
Bundle 对象具有请求属性。
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-tastypie: Cannot access bundle.request in dehydrate(self,bundle)
在上面的问题中我发现,使用 0.9.10 是不够的,版本 1.0.0 beta 应该可以做到这一点..
【讨论】: