diff --git a/django/forms/forms.py b/django/forms/forms.py index dd562099ab..3898419ab2 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -11,6 +11,7 @@ from django.forms.fields import Field, FileField # pretty_name is imported for backwards compatibility in Django 1.9 from django.forms.utils import ErrorDict, ErrorList, pretty_name # NOQA from django.forms.widgets import Media, MediaDefiningClass +from django.utils.datastructures import MultiValueDict from django.utils.functional import cached_property from django.utils.html import conditional_escape, html_safe from django.utils.safestring import mark_safe @@ -69,8 +70,8 @@ class BaseForm: initial=None, error_class=ErrorList, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None): self.is_bound = data is not None or files is not None - self.data = {} if data is None else data - self.files = {} if files is None else files + self.data = MultiValueDict() if data is None else data + self.files = MultiValueDict() if files is None else files self.auto_id = auto_id if prefix is not None: self.prefix = prefix diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index d4e421d6ac..edce5e801f 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -3671,6 +3671,11 @@ Good luck picking a username that doesn't already exist.

self.assertTrue(f.is_valid()) self.assertEqual(f.cleaned_data, {'data': 'xyzzy'}) + def test_empty_data_files_multi_value_dict(self): + p = Person() + self.assertIsInstance(p.data, MultiValueDict) + self.assertIsInstance(p.files, MultiValueDict) + class CustomRenderer(DjangoTemplates): pass