From 75199e8f6d96887c10ba79870428e04ed34e1ca5 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Wed, 21 Sep 2011 14:20:18 +0000 Subject: [PATCH] Fixed #16866 -- Clearer error message if empty list is passed to select_template. Thanks Silver_Ghost for report and patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16861 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/loader.py | 2 ++ tests/regressiontests/templates/loaders.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/django/template/loader.py b/django/template/loader.py index e10533393d6..418501713db 100644 --- a/django/template/loader.py +++ b/django/template/loader.py @@ -179,6 +179,8 @@ def render_to_string(template_name, dictionary=None, context_instance=None): def select_template(template_name_list): "Given a list of template names, returns the first that can be loaded." + if not template_name_list: + raise TemplateDoesNotExist("No template names provided") not_found = [] for template_name in template_name_list: try: diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py index c2ae0bd1fcd..45131bf2655 100644 --- a/tests/regressiontests/templates/loaders.py +++ b/tests/regressiontests/templates/loaders.py @@ -143,5 +143,16 @@ class RenderToStringTest(unittest.TestCase): self.assertEqual(output, 'obj:after') self.assertEqual(context['obj'], 'before') + def test_empty_list(self): + self.assertRaisesRegexp(TemplateDoesNotExist, + 'No template names provided$', + loader.render_to_string, []) + + + def test_select_templates_from_empty_list(self): + self.assertRaisesRegexp(TemplateDoesNotExist, + 'No template names provided$', + loader.select_template, []) + if __name__ == "__main__": unittest.main()