Refs #33396 -- Added django.views.debug.get_caller() hook.

This commit is contained in:
Hrushikesh Vaidya 2022-01-13 06:49:42 +01:00 committed by Mariusz Felisiak
parent 90cf963264
commit 4099e6e737
1 changed files with 11 additions and 8 deletions

View File

@ -85,6 +85,16 @@ def get_exception_reporter_class(request):
return getattr(request, 'exception_reporter_class', default_exception_reporter_class)
def get_caller(request):
resolver_match = request.resolver_match
if resolver_match is None:
try:
resolver_match = resolve(request.path)
except Http404:
pass
return '' if resolver_match is None else resolver_match._func_path
class SafeExceptionReporterFilter:
"""
Use annotations made by the sensitive_post_parameters and
@ -536,13 +546,6 @@ def technical_404_response(request, exception):
if isinstance(urlconf, types.ModuleType):
urlconf = urlconf.__name__
resolver_match = request.resolver_match
if resolver_match is None:
try:
resolver_match = resolve(request.path)
except Http404:
pass
with builtin_template_path('technical_404.html').open(encoding='utf-8') as fh:
t = DEBUG_ENGINE.from_string(fh.read())
reporter_filter = get_default_exception_reporter_filter()
@ -555,7 +558,7 @@ def technical_404_response(request, exception):
'reason': str(exception),
'request': request,
'settings': reporter_filter.get_safe_settings(),
'raising_view_name': '' if resolver_match is None else resolver_match._func_path,
'raising_view_name': get_caller(request),
})
return HttpResponseNotFound(t.render(c), content_type='text/html')