From 2a66c102d9c674fadab252a28d8def32a8b626ec Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Fri, 7 Jan 2022 12:57:03 +0000 Subject: [PATCH] Fixed #33425 -- Fixed view name for CBVs on technical 404 debug page. Regression in 0c0b87725bbcffca3bc3a7a2c649995695a5ae3b. --- django/views/debug.py | 5 +++-- docs/releases/4.0.2.txt | 3 +++ tests/view_tests/tests/test_debug.py | 14 +++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/django/views/debug.py b/django/views/debug.py index da9a17e60f..cff199ddb4 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, + '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, + 'Raised by:view_tests.views.Http404View', + status_code=404, + html=True, + ) def test_non_l10ned_numeric_ids(self): """