diff --git a/AUTHORS b/AUTHORS index c343eeb67b..85b046650a 100644 --- a/AUTHORS +++ b/AUTHORS @@ -471,6 +471,7 @@ answer newbie questions, and generally made Django that much better: phil@produxion.net phil.h.smith@gmail.com Gustavo Picon + Andrew Pinkham Travis Pinney Michael Placentra II plisk @@ -635,6 +636,7 @@ answer newbie questions, and generally made Django that much better: Derek Willis Rachel Willmer Jakub Wilk + Ian A Wilson Jakub Wiśniowski Maciej Wiśniowski wojtek diff --git a/django/views/debug.py b/django/views/debug.py index 16f75df8c3..6a0f81876e 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -233,6 +233,10 @@ class ExceptionReporter(object): from django.template.loader import template_source_loaders self.template_does_not_exist = True 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: try: source_list_func = loader.get_template_sources diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index e941f4ae0e..6bbdbbea33 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -14,6 +14,9 @@ from unittest import skipIf from django.core import mail from django.core.files.uploadedfile import SimpleUploadedFile from django.core.urlresolvers import reverse +from django.http import HttpRequest +from django.shortcuts import render +from django.template.base import TemplateDoesNotExist from django.test import TestCase, RequestFactory from django.test.utils import (override_settings, setup_test_template_loader, restore_template_loaders) @@ -129,6 +132,12 @@ class DebugViewTests(TestCase): finally: 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): rf = RequestFactory() diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py index 4db3e262ed..e3ec63c289 100644 --- a/tests/view_tests/urls.py +++ b/tests/view_tests/urls.py @@ -68,4 +68,5 @@ urlpatterns += patterns('view_tests.views', url(r'view_exception/(?P\d+)/$', 'view_exception', name='view_exception'), url(r'template_exception/(?P\d+)/$', 'template_exception', name='template_exception'), url(r'^raises_template_does_not_exist/(?P.+)$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'), + url(r'^render_no_template/$', 'render_no_template', name='render_no_template'), ) diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py index 04924bc9f7..c21520eaa7 100644 --- a/tests/view_tests/views.py +++ b/tests/view_tests/views.py @@ -131,6 +131,11 @@ def raises_template_does_not_exist(request, path='i_dont_exist.html'): except TemplateDoesNotExist: 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): logger = getLogger('django.request') # The default logging config has a logging filter to ensure admin emails are