Merge pull request #1579 from ianawilson/ticket_21058

Fixed #21058 -- Fixed debug view blowing up when no template is provided to the template rendering functions.

Assistance on this commit from @jambonrose.
This commit is contained in:
Russell Keith-Magee 2013-09-06 15:06:57 -07:00
commit 122020fdb9
5 changed files with 19 additions and 0 deletions

View File

@ -472,6 +472,7 @@ answer newbie questions, and generally made Django that much better:
phil@produxion.net phil@produxion.net
phil.h.smith@gmail.com phil.h.smith@gmail.com
Gustavo Picon Gustavo Picon
Andrew Pinkham <http://AndrewsForge.com>
Travis Pinney Travis Pinney
Michael Placentra II <someone@michaelplacentra2.net> Michael Placentra II <someone@michaelplacentra2.net>
plisk plisk
@ -636,6 +637,7 @@ answer newbie questions, and generally made Django that much better:
Derek Willis <http://blog.thescoop.org/> Derek Willis <http://blog.thescoop.org/>
Rachel Willmer <http://www.willmer.com/kb/> Rachel Willmer <http://www.willmer.com/kb/>
Jakub Wilk <ubanus@users.sf.net> Jakub Wilk <ubanus@users.sf.net>
Ian A Wilson <http://ianawilson.com>
Jakub Wiśniowski <restless.being@gmail.com> Jakub Wiśniowski <restless.being@gmail.com>
Maciej Wiśniowski <pigletto@gmail.com> Maciej Wiśniowski <pigletto@gmail.com>
wojtek wojtek

View File

@ -233,6 +233,10 @@ class ExceptionReporter(object):
from django.template.loader import template_source_loaders from django.template.loader import template_source_loaders
self.template_does_not_exist = True self.template_does_not_exist = True
self.loader_debug_info = [] self.loader_debug_info = []
# If the template_source_loaders haven't been populated yet, you need
# to provide an empty list for this for loop to not fail.
if template_source_loaders is None:
template_source_loaders = []
for loader in template_source_loaders: for loader in template_source_loaders:
try: try:
source_list_func = loader.get_template_sources source_list_func = loader.get_template_sources

View File

@ -14,6 +14,7 @@ from unittest import skipIf
from django.core import mail from django.core import mail
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.template.base import TemplateDoesNotExist
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from django.test.utils import (override_settings, setup_test_template_loader, from django.test.utils import (override_settings, setup_test_template_loader,
restore_template_loaders) restore_template_loaders)
@ -129,6 +130,12 @@ class DebugViewTests(TestCase):
finally: finally:
shutil.rmtree(template_path) shutil.rmtree(template_path)
def test_no_template_source_loaders(self):
"""
Make sure if you don't specify a template, the debug view doesn't blow up.
"""
self.assertRaises(TemplateDoesNotExist, self.client.get, '/render_no_template/')
class ExceptionReporterTests(TestCase): class ExceptionReporterTests(TestCase):
rf = RequestFactory() rf = RequestFactory()

View File

@ -68,4 +68,5 @@ urlpatterns += patterns('view_tests.views',
url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'), 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'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'),
url(r'^raises_template_does_not_exist/(?P<path>.+)$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'), url(r'^raises_template_does_not_exist/(?P<path>.+)$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'),
url(r'^render_no_template/$', 'render_no_template', name='render_no_template'),
) )

View File

@ -131,6 +131,11 @@ def raises_template_does_not_exist(request, path='i_dont_exist.html'):
except TemplateDoesNotExist: except TemplateDoesNotExist:
return technical_500_response(request, *sys.exc_info()) return technical_500_response(request, *sys.exc_info())
def render_no_template(request):
# If we do not specify a template, we need to make sure the debug
# view doesn't blow up.
return render(request, [], {})
def send_log(request, exc_info): def send_log(request, exc_info):
logger = getLogger('django.request') logger = getLogger('django.request')
# The default logging config has a logging filter to ensure admin emails are # The default logging config has a logging filter to ensure admin emails are