diff --git a/django/forms/templates/django/forms/widgets/attrs.html b/django/forms/templates/django/forms/widgets/attrs.html index c8bba9f35c..7a5592afcb 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 %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value }}"{% endif %}{% endif %}{% endfor %} \ No newline at end of file +{% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %} \ No newline at end of file diff --git a/docs/releases/1.11.3.txt b/docs/releases/1.11.3.txt index 5ff33e42e6..1e2ddddb66 100644 --- a/docs/releases/1.11.3.txt +++ b/docs/releases/1.11.3.txt @@ -40,3 +40,7 @@ Bugfixes context. It's now an empty string (as it is for the original function-based ``login()`` view) if the corresponding parameter isn't sent in a request (in particular, when the login page is accessed directly) (:ticket:`28229`). + +* Prevented attribute values in the ``django/forms/widgets/attrs.html`` + template from being localized so that numeric attributes (e.g. ``max`` and + ``min``) of ``NumberInput`` work correctly (:ticket:`28303`). diff --git a/tests/forms_tests/widget_tests/test_numberinput.py b/tests/forms_tests/widget_tests/test_numberinput.py new file mode 100644 index 0000000000..95a0a9250a --- /dev/null +++ b/tests/forms_tests/widget_tests/test_numberinput.py @@ -0,0 +1,15 @@ +from django.forms.widgets import NumberInput +from django.test import override_settings + +from .base import WidgetTest + + +class NumberInputTests(WidgetTest): + + @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + def test_attrs_not_localized(self): + widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999}) + self.check_html( + widget, 'name', 'value', + '' + )