diff --git a/django/forms/jinja2/django/forms/widgets/attrs.html b/django/forms/jinja2/django/forms/widgets/attrs.html index b45d30c449..7fbda39ce5 100644 --- a/django/forms/jinja2/django/forms/widgets/attrs.html +++ b/django/forms/jinja2/django/forms/widgets/attrs.html @@ -1 +1 @@ -{% for name, value in widget.attrs.items() %} {{ name }}{% if not value is sameas True %}="{{ value }}"{% endif %}{% endfor %} +{% for name, value in widget.attrs.items() %}{% if value is not sameas False %} {{ name }}{% if not value is sameas True %}="{{ value }}"{% endif %}{% endif %}{% endfor %} diff --git a/django/forms/templates/django/forms/widgets/attrs.html b/django/forms/templates/django/forms/widgets/attrs.html index caca0cd80c..fdb1a56d90 100644 --- a/django/forms/templates/django/forms/widgets/attrs.html +++ b/django/forms/templates/django/forms/widgets/attrs.html @@ -1 +1 @@ -{% for name, value in widget.attrs.items %} {{ name }}{% if not value is True %}="{{ value }}"{% endif %}{% endfor %} \ No newline at end of file +{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if not value is True %}="{{ value }}"{% endif %}{% endif %}{% endfor %} \ No newline at end of file diff --git a/tests/forms_tests/widget_tests/test_widget.py b/tests/forms_tests/widget_tests/test_widget.py index 368c315be7..3ad3c23a48 100644 --- a/tests/forms_tests/widget_tests/test_widget.py +++ b/tests/forms_tests/widget_tests/test_widget.py @@ -13,3 +13,7 @@ class WidgetTests(WidgetTest): def test_no_trailing_newline_in_attrs(self): self.check_html(Input(), 'name', 'value', strict=True, html='') + + def test_attr_false_not_rendered(self): + html = '' + self.check_html(Input(), 'name', 'value', html=html, attrs={'readonly': False})