diff --git a/django/forms/utils.py b/django/forms/utils.py index dc4df86058..88086b2c64 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -40,7 +40,7 @@ def flatatt(attrs): if isinstance(value, bool): if value: boolean_attrs.append((attr,)) - else: + elif value is not None: key_value_attrs.append((attr, value)) return ( diff --git a/tests/forms_tests/tests/test_utils.py b/tests/forms_tests/tests/test_utils.py index a6a2d81b9f..f95c956322 100644 --- a/tests/forms_tests/tests/test_utils.py +++ b/tests/forms_tests/tests/test_utils.py @@ -34,6 +34,7 @@ class FormsUtilsTestCase(SimpleTestCase): flatatt({'class': "news", 'title': "Read this", 'required': False}), ' class="news" title="Read this"' ) + self.assertEqual(flatatt({'class': None}), '') self.assertEqual(flatatt({}), '') def test_flatatt_no_side_effects(self):