Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request.files raises AttributeError #3261

Closed
Gwildor opened this issue Aug 11, 2015 · 2 comments
Closed

request.files raises AttributeError #3261

Gwildor opened this issue Aug 11, 2015 · 2 comments
Labels
Milestone

Comments

@Gwildor
Copy link

Gwildor commented Aug 11, 2015

This might just be me being confused, or an error in the docs. I'm on 3.2.1, and I'm trying to handle uploading files, using request.files as it says I should do in the 3.2 announcement. I'm aware that because of #3239 request.FILES still works, but I'm trying to use the more favourable attribute. However, this gives me an AttributeError, for some reason:

ipdb> type(request)
<class 'rest_framework.request.Request'>
ipdb> request.files
*** AttributeError: 'Request' object has no attribute 'files'
ipdb> request.FILES
<MultiValueDict: {'x.jpg': [<InMemoryUploadedFile: x.jpg (application/octet-stream)>]}>
ipdb> request.data
<QueryDict: {'x.jpg': [<InMemoryUploadedFile: x.jpg (application/octet-stream)>]}>
ipdb> request.DATA
*** NotImplementedError: `request.DATA` has been deprecated in favor of `request.data` since version 3.0, and has been fully removed as of version 3.2.
ipdb> from rest_framework import __version__
ipdb> __version__
'3.2.1'

Using request.data instead of request.DATA seems to work fine. I'm working in a view which subclasses GenericAPIView directly, and also uses the post method directly for direct request and response handling.

There is also in inconsistency in the docs. In the announcement of 3.2, it says "request.FILES was put on the deprecation path in 3.0. It has now been removed and its usage will result in an error. Use the more pythonic style of request.files instead.". However, in the Requests section of the API guide, it says "The old-style version 2.x request.DATA and request.FILES attributes are still available, but are now pending deprecation in favor of the unified request.data attribute.". This seems inconsistent to me, because it makes me think I shouldn't use request.files at all, but only request.data.

@tomchristie
Copy link
Member

Yup, this is me having a major brain-fail. Apologies, not sure why I thought .files was a thing while writing the release announcement. :-/

Use request.data - contains all parsed content.

@Gwildor
Copy link
Author

Gwildor commented Aug 11, 2015

Alright, will do. Thanks for the insanely fast response!

@tomchristie tomchristie added this to the 3.2.2 Release milestone Aug 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants