Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adds fix and test for when a template is not specified at all to rend…

…er(). fixes #21058. by jambonrose and ianawilson
  • Loading branch information...
commit 9b7f4aab326067a3ad503887a4e42c9d76d0bc25 1 parent 630eb05
Ian A Wilson authored September 06, 2013
2  AUTHORS
@@ -471,6 +471,7 @@ answer newbie questions, and generally made Django that much better:
471 471
     phil@produxion.net
472 472
     phil.h.smith@gmail.com
473 473
     Gustavo Picon
  474
+    Andrew Pinkham <http://AndrewsForge.com>
474 475
     Travis Pinney
475 476
     Michael Placentra II <someone@michaelplacentra2.net>
476 477
     plisk
@@ -635,6 +636,7 @@ answer newbie questions, and generally made Django that much better:
635 636
     Derek Willis <http://blog.thescoop.org/>
636 637
     Rachel Willmer <http://www.willmer.com/kb/>
637 638
     Jakub Wilk <ubanus@users.sf.net>
  639
+    Ian A Wilson <http://ianawilson.com>
638 640
     Jakub Wiśniowski <restless.being@gmail.com>
639 641
     Maciej Wiśniowski <pigletto@gmail.com>
640 642
     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
9  tests/view_tests/tests/test_debug.py
@@ -14,6 +14,9 @@
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.http import HttpRequest
  18
+from django.shortcuts import render
  19
+from django.template.base import TemplateDoesNotExist
17 20
 from django.test import TestCase, RequestFactory
18 21
 from django.test.utils import (override_settings, setup_test_template_loader,
19 22
     restore_template_loaders)
@@ -129,6 +132,12 @@ def test_template_loader_postmortem_notafile(self):
129 132
         finally:
130 133
             shutil.rmtree(template_path)
131 134
 
  135
+    def test_no_template_source_loaders(self):
  136
+        """
  137
+        Make sure if you don't specify a template, the debug view doesn't blow up.
  138
+        """
  139
+        self.assertRaises(TemplateDoesNotExist, self.client.get, '/render_no_template/')
  140
+
132 141
 
133 142
 class ExceptionReporterTests(TestCase):
134 143
     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 9b7f4aa

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