Skip to content

Commit

Permalink
Fixed #16866 -- Clearer error message if empty list is passed to sele…
Browse files Browse the repository at this point in the history
…ct_template. Thanks Silver_Ghost for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16861 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
carljm committed Sep 21, 2011
1 parent 09a0143 commit 75199e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions django/template/loader.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def render_to_string(template_name, dictionary=None, context_instance=None):


def select_template(template_name_list): def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded." "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 = [] not_found = []
for template_name in template_name_list: for template_name in template_name_list:
try: try:
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/templates/loaders.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -143,5 +143,16 @@ def test_existing_context_kept_clean(self):
self.assertEqual(output, 'obj:after') self.assertEqual(output, 'obj:after')
self.assertEqual(context['obj'], 'before') 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__": if __name__ == "__main__":
unittest.main() unittest.main()

0 comments on commit 75199e8

Please sign in to comment.