diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index a1b08e0921..b18b41c293 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -223,9 +223,9 @@ def stringformat(value, arg): See https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting for documentation of Python string formatting. """ + if isinstance(value, tuple): + value = str(value) try: - if isinstance(value, tuple): - return ('%' + str(arg)) % str(value) return ("%" + str(arg)) % value except (ValueError, TypeError): return "" diff --git a/docs/releases/1.11.5.txt b/docs/releases/1.11.5.txt index 556cc73793..e7c6c91a5d 100644 --- a/docs/releases/1.11.5.txt +++ b/docs/releases/1.11.5.txt @@ -13,3 +13,5 @@ Bugfixes in GEOS 3.6.2) (:ticket:`28441`). * Fixed test database creation with ``cx_Oracle`` 6 (:ticket:`28498`). + +* Fixed select widget rendering when option values are tuples (:ticket:`28502`). diff --git a/tests/template_tests/filter_tests/test_stringformat.py b/tests/template_tests/filter_tests/test_stringformat.py index 8efa5e0599..62ee19aef8 100644 --- a/tests/template_tests/filter_tests/test_stringformat.py +++ b/tests/template_tests/filter_tests/test_stringformat.py @@ -39,3 +39,4 @@ class FunctionTests(SimpleTestCase): self.assertEqual(stringformat(1, 'z'), '') self.assertEqual(stringformat(object(), 'd'), '') self.assertEqual(stringformat(None, 'd'), '') + self.assertEqual(stringformat((1, 2, 3), 'd'), '')