From 5fa390ee81c5a963fc4476e8de6c1e5e1fc57e22 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 22 Jan 2017 10:15:56 -0800 Subject: [PATCH] Fixed #27759 -- Prevented forms attrs.html template from rendering False attrs. Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01. --- django/forms/jinja2/django/forms/widgets/attrs.html | 2 +- django/forms/templates/django/forms/widgets/attrs.html | 2 +- tests/forms_tests/widget_tests/test_widget.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) 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})