-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
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.