我需要在我的资源的脱水方法中访问 HttpRequest 对象。
在文档中,它显示 bundle.request 是一个有效的属性(它在 resources.html 页面中)。当我尝试将它添加到我的代码中时,我收到一个错误,声称 Bundle' 对象没有属性 '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()
无论如何,您可以将 Resource 方法设置为高于dehydrate
调用堆栈中的方法。
你能显示代码吗?
我刚刚遇到了同样的问题,但在这里找到了正确的答案: 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:无法在脱水(自我,捆绑)中访问 bundle.request
在上面的问题中我发现,使用 0.9.10 是不够的,版本 1.0.0 beta 应该可以解决问题。