[Django]-Django โ€“ sometimes request.POST is mutable, sometimes it isn't

4๐Ÿ‘

โœ…

By default it should always be False, the only place in the Django code that sets it to True is in the MultiPartParser.parse, which only happens if the CONTENT_TYPE starts with multipart.

From _load_post_and_files in HttpRequest:

if self.META.get('CONTENT_TYPE', '').startswith('multipart'):
    self._raw_post_data = ''
    try:
        self._post, self._files = self.parse_file_upload(self.META, self)
        ...

From parse_file_upload:

parser = MultiPartParser(META, post_data, self.upload_handlers, self.encoding)
return parser.parse()

And from MultiPartParser.parse:

self._post = QueryDict('', mutable=True)
...
return self._post, self._files

So if one view is getting multipart requests and the other is not, that would explain the difference.

๐Ÿ‘คDaniel DiPaolo

Leave a comment