diff --git a/django/views/debug.py b/django/views/debug.py index 16c9ad7fc8..2a4593e87e 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -545,8 +545,9 @@ def technical_404_response(request, exception): obj = resolver_match.func if hasattr(obj, 'view_class'): - caller = obj.view_class - elif hasattr(obj, '__name__'): + obj = obj.view_class + + if hasattr(obj, '__name__'): caller = obj.__name__ elif hasattr(obj, '__class__') and hasattr(obj.__class__, '__name__'): caller = obj.__class__.__name__ diff --git a/docs/releases/4.0.2.txt b/docs/releases/4.0.2.txt index 21b1a56884..71bb71e91d 100644 --- a/docs/releases/4.0.2.txt +++ b/docs/releases/4.0.2.txt @@ -14,3 +14,6 @@ Bugfixes * Fixed a regression in Django 4.0 where ``help_text`` was HTML-escaped in automatically-generated forms (:ticket:`33419`). + +* Fixed a regression in Django 4.0 that caused displaying an incorrect name for + class-based views on the technical 404 debug page (:ticket:`33425`). diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 5ceb7fc39e..7c49fa51f3 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -177,7 +177,11 @@ class DebugViewTests(SimpleTestCase): html=True, ) self.assertContains(response, "Raised by:", status_code=404) - self.assertContains(response, "view_tests.views.technical404", status_code=404) + self.assertContains( + response, + '
The current path, technical404/
, matched the '
@@ -188,8 +192,12 @@ class DebugViewTests(SimpleTestCase):
def test_classbased_technical_404(self):
response = self.client.get('/classbased404/')
- self.assertContains(response, "Raised by:", status_code=404)
- self.assertContains(response, "view_tests.views.Http404View", status_code=404)
+ self.assertContains(
+ response,
+ '