Support request.FILES in process_as_post.

(imported from commit 646019b5efe4ae3f6f66f99f76f2036d9fd9ec8e)
This commit is contained in:
Steve Howell 2013-08-01 13:33:30 -04:00
parent a02fe71788
commit 2b28cf9a0a
1 changed files with 5 additions and 2 deletions

View File

@ -141,8 +141,11 @@ def process_as_post(view_func):
if not request.POST: if not request.POST:
# Only take action if POST is empty. # Only take action if POST is empty.
if request.META.get('CONTENT_TYPE', '').startswith('multipart'): if request.META.get('CONTENT_TYPE', '').startswith('multipart'):
request.POST = MultiPartParser(request.META, StringIO(request.body), # Note that request._files is just the private attribute that backs the
[], request.encoding).parse()[0] # FILES property, so we are essentially setting request.FILES here. (In
# Django 1.5 FILES was still a read-only property.)
request.POST, request._files = MultiPartParser(request.META, StringIO(request.body),
request.upload_handlers, request.encoding).parse()
else: else:
request.POST = QueryDict(request.body, encoding=request.encoding) request.POST = QueryDict(request.body, encoding=request.encoding)