Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #15122 -- Restored reporting of the template files trie…

…d in the texmplate loader post mortem section of the TemplateDoesNotExit 500 error debug page. Thanks rdrey for reporting this regression.

Backport of [15252] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15253 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit cf7157a7a4d0ecab2e9679d3d6eabf4a02aea65d 1 parent 0958f32
@ramiro ramiro authored
View
11 django/views/debug.py
@@ -88,17 +88,18 @@ def get_traceback_html(self):
for loader in template_source_loaders:
try:
module = import_module(loader.__module__)
- source_list_func = module.get_template_sources
+ if hasattr(loader, '__class__'):
+ source_list_func = loader.get_template_sources
+ loader_name = loader.__module__ + '.' + loader.__class__.__name__
+ else: # NOTE: Remember to remove this branch when we deprecate old template loaders in 1.4
+ source_list_func = module.get_template_sources
+ loader_name = loader.__module__ + '.' + loader.__name__
# NOTE: This assumes exc_value is the name of the template that
# the loader attempted to load.
template_list = [{'name': t, 'exists': os.path.exists(t)} \
for t in source_list_func(str(self.exc_value))]
except (ImportError, AttributeError):
template_list = []
- if hasattr(loader, '__class__'):
- loader_name = loader.__module__ + '.' + loader.__class__.__name__
- else:
- loader_name = loader.__module__ + '.' + loader.__name__
self.loader_debug_info.append({
'loader': loader_name,
'templates': template_list,
View
4 tests/regressiontests/views/tests/debug.py
@@ -48,3 +48,7 @@ def test_template_exceptions(self):
self.assertFalse(raising_loc.find('raise BrokenException') == -1,
"Failed to find 'raise BrokenException' in last frame of traceback, instead found: %s" %
raising_loc)
+
+ def test_template_loader_postmortem(self):
+ response = self.client.get(reverse('raises_template_does_not_exist'))
+ self.assertContains(response, 'templates/i_dont_exist.html</code> (File does not exist)</li>', status_code=500)
View
1  tests/regressiontests/views/urls.py
@@ -128,4 +128,5 @@
urlpatterns += patterns('regressiontests.views.views',
url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'),
url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'),
+ url(r'^raises_template_does_not_exist/$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'),
)
View
15 tests/regressiontests/views/views.py
@@ -1,11 +1,12 @@
import sys
-from django.http import HttpResponse, HttpResponseRedirect
from django import forms
-from django.views.debug import technical_500_response
-from django.views.generic.create_update import create_object
+from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import get_resolver
from django.shortcuts import render_to_response
+from django.template import TemplateDoesNotExist
+from django.views.debug import technical_500_response
+from django.views.generic.create_update import create_object
from regressiontests.views import BrokenException, except_args
@@ -57,3 +58,11 @@ def template_exception(request, n):
return render_to_response('debug/template_exception.html',
{'arg': except_args[int(n)]})
+def raises_template_does_not_exist(request):
+ # We need to inspect the HTML generated by the fancy 500 debug view but
+ # the test client ignores it, so we send it explicitly.
+ try:
+ return render_to_response('i_dont_exist.html')
+ except TemplateDoesNotExist:
+ return technical_500_response(request, *sys.exc_info())
+
Please sign in to comment.
Something went wrong with that request. Please try again.