Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 122020fdb93980df850ae02f61d97da27e2cb515 2 parents e844e10 + e12de0a
Russell Keith-Magee authored September 06, 2013
2  AUTHORS
@@ -472,6 +472,7 @@ answer newbie questions, and generally made Django that much better:
472 472
     phil@produxion.net
473 473
     phil.h.smith@gmail.com
474 474
     Gustavo Picon
  475
+    Andrew Pinkham <http://AndrewsForge.com>
475 476
     Travis Pinney
476 477
     Michael Placentra II <someone@michaelplacentra2.net>
477 478
     plisk
@@ -636,6 +637,7 @@ answer newbie questions, and generally made Django that much better:
636 637
     Derek Willis <http://blog.thescoop.org/>
637 638
     Rachel Willmer <http://www.willmer.com/kb/>
638 639
     Jakub Wilk <ubanus@users.sf.net>
  640
+    Ian A Wilson <http://ianawilson.com>
639 641
     Jakub Wiśniowski <restless.being@gmail.com>
640 642
     Maciej Wiśniowski <pigletto@gmail.com>
641 643
     wojtek
4  django/views/debug.py
@@ -233,6 +233,10 @@ def get_traceback_data(self):
233 233
             from django.template.loader import template_source_loaders
234 234
             self.template_does_not_exist = True
235 235
             self.loader_debug_info = []
  236
+            # If the template_source_loaders haven't been populated yet, you need
  237
+            # to provide an empty list for this for loop to not fail.
  238
+            if template_source_loaders is None:
  239
+                template_source_loaders = []
236 240
             for loader in template_source_loaders:
237 241
                 try:
238 242
                     source_list_func = loader.get_template_sources
7  tests/view_tests/tests/test_debug.py
@@ -14,6 +14,7 @@
14 14
 from django.core import mail
15 15
 from django.core.files.uploadedfile import SimpleUploadedFile
16 16
 from django.core.urlresolvers import reverse
  17
+from django.template.base import TemplateDoesNotExist
17 18
 from django.test import TestCase, RequestFactory
18 19
 from django.test.utils import (override_settings, setup_test_template_loader,
19 20
     restore_template_loaders)
@@ -129,6 +130,12 @@ def test_template_loader_postmortem_notafile(self):
129 130
         finally:
130 131
             shutil.rmtree(template_path)
131 132
 
  133
+    def test_no_template_source_loaders(self):
  134
+        """
  135
+        Make sure if you don't specify a template, the debug view doesn't blow up.
  136
+        """
  137
+        self.assertRaises(TemplateDoesNotExist, self.client.get, '/render_no_template/')
  138
+
132 139
 
133 140
 class ExceptionReporterTests(TestCase):
134 141
     rf = RequestFactory()
1  tests/view_tests/urls.py
@@ -68,4 +68,5 @@
68 68
     url(r'view_exception/(?P<n>\d+)/$', 'view_exception', name='view_exception'),
69 69
     url(r'template_exception/(?P<n>\d+)/$', 'template_exception', name='template_exception'),
70 70
     url(r'^raises_template_does_not_exist/(?P<path>.+)$', 'raises_template_does_not_exist', name='raises_template_does_not_exist'),
  71
+    url(r'^render_no_template/$', 'render_no_template', name='render_no_template'),
71 72
 )
5  tests/view_tests/views.py
@@ -131,6 +131,11 @@ def raises_template_does_not_exist(request, path='i_dont_exist.html'):
131 131
     except TemplateDoesNotExist:
132 132
         return technical_500_response(request, *sys.exc_info())
133 133
 
  134
+def render_no_template(request):
  135
+    # If we do not specify a template, we need to make sure the debug
  136
+    # view doesn't blow up.
  137
+    return render(request, [], {})
  138
+
134 139
 def send_log(request, exc_info):
135 140
     logger = getLogger('django.request')
136 141
     # The default logging config has a logging filter to ensure admin emails are

0 notes on commit 122020f

Please sign in to comment.
Something went wrong with that request. Please try again.