Django-Tastypie: how do you request a request object (Http) in a bundle?

I need to access the HttpRequest object in my dehydration resource method.

The docs show that bundle.request is a valid attribute (it on the resources.html page). When I try to add it to my code, I get an error stating that the Bundle object does not have a request attribute. What gives?

+3
source share
2 answers

I had the same problem, but I found the correct answer: http://groups.google.com/group/django-tastypie/tree/browse_frm/thread/801f44af3f2dbe7b/a36f303380eacf96

It seems django-tasty-pie version 0.9.9 does not have this attribute, but version 0.9.10 does!

so if you use buildout, look at buildout.cfg by version: search django-tastypie = 0.9.9

remove this and see your installation select or replace it:

 django-tastypie = 0.9.10 

I still have this problem, so a new link opened:

django-tastypie: cannot access bundle.request in dehydrate (self, bundle)

in the above question, I found out that using 0.9.10 is not enough, version 1.0.0 beta should do tric ..

+2
source

The Bundle object has a request attribute.

 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() 

Anyway, you can ovveride the resource method higher than dehydrate in the call stack.

Could you show the code?

+3
source

Source: https://habr.com/ru/post/902204/


All Articles