From 0c0b87725bbcffca3bc3a7a2c649995695a5ae3b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Wed, 17 Mar 2021 10:55:00 +0000 Subject: [PATCH] Refs #32260 -- Made admindocs and technical 404 debug page use view_func.view_class. Internals of admindocs and technical 404 debug page should use the view_class attribute and do not rely on __name__. --- django/contrib/admindocs/utils.py | 3 +++ django/urls/resolvers.py | 4 +++- django/views/debug.py | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py index 9f6666535d..8cb789016f 100644 --- a/django/contrib/admindocs/utils.py +++ b/django/contrib/admindocs/utils.py @@ -20,6 +20,9 @@ else: def get_view_name(view_func): + if hasattr(view_func, 'view_class'): + klass = view_func.view_class + return f'{klass.__module__}.{klass.__qualname__}' mod_name = view_func.__module__ view_name = getattr(view_func, '__qualname__', view_func.__class__.__name__) return mod_name + '.' + view_name diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py index 0912a82f14..fac77fc4bc 100644 --- a/django/urls/resolvers.py +++ b/django/urls/resolvers.py @@ -378,7 +378,9 @@ class URLPattern: callback = self.callback if isinstance(callback, functools.partial): callback = callback.func - if not hasattr(callback, '__name__'): + if hasattr(callback, 'view_class'): + callback = callback.view_class + elif not hasattr(callback, '__name__'): return callback.__module__ + "." + callback.__class__.__name__ return callback.__module__ + "." + callback.__qualname__ diff --git a/django/views/debug.py b/django/views/debug.py index e2f9ffe3e2..36abaf3121 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -517,7 +517,9 @@ def technical_404_response(request, exception): else: obj = resolver_match.func - if hasattr(obj, '__name__'): + if hasattr(obj, 'view_class'): + caller = obj.view_class + elif hasattr(obj, '__name__'): caller = obj.__name__ elif hasattr(obj, '__class__') and hasattr(obj.__class__, '__name__'): caller = obj.__class__.__name__