summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2024-12-09 11:17:25 +0000
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-12-10 12:13:43 +0100
commit02628c051c18d000256424daffe996c22bed5ae3 (patch)
tree03d57b02488081d0220fb6bbfe4d72414b914f76
parent1860a1afc9ac20750f932e8e0a94b32d096f2848 (diff)
Fixed #35988 -- Made BaseForm.full_clean() pass renderer to ErrorDict.
-rw-r--r--django/forms/forms.py2
-rw-r--r--tests/forms_tests/tests/test_forms.py16
2 files changed, 17 insertions, 1 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 549a3adf6f..614f990395 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -316,7 +316,7 @@ class BaseForm(RenderableFormMixin):
"""
Clean all of self.data and populate self._errors and self.cleaned_data.
"""
- self._errors = ErrorDict()
+ self._errors = ErrorDict(renderer=self.renderer)
if not self.is_bound: # Stop further processing.
return
self.cleaned_data = {}
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index cd909628cb..d88ac33f24 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -5313,6 +5313,22 @@ class OverrideTests(SimpleTestCase):
"required></p>",
)
+ def test_custom_renderer_error_dict(self):
+ class CustomRenderer(DjangoTemplates):
+ def render(self, template_name, context, request=None):
+ if template_name == "django/forms/errors/dict/default.html":
+ return "<strong>So many errors!</strong>"
+ return super().render(template_name, context, request)
+
+ form = Form({}, renderer=CustomRenderer())
+ form.full_clean()
+ form.add_error(None, "Test error")
+
+ self.assertHTMLEqual(
+ form.errors.render(),
+ "<strong>So many errors!</strong>",
+ )
+
def test_cyclic_context_boundfield_render(self):
class FirstNameForm(Form):
first_name = CharField()