mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #26109 -- Raised a helpful error if loader.select_tamplate() is passed a string.
This commit is contained in:
parent
275d11fbc5
commit
229488c8a1
@ -33,6 +33,13 @@ def select_template(template_name_list, using=None):
|
|||||||
|
|
||||||
Raises TemplateDoesNotExist if no such template exists.
|
Raises TemplateDoesNotExist if no such template exists.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(template_name_list, six.string_types):
|
||||||
|
raise TypeError(
|
||||||
|
'select_template() takes an iterable of template names but got a '
|
||||||
|
'string: %r. Use get_template() if you want to load a single '
|
||||||
|
'template by name.' % template_name_list
|
||||||
|
)
|
||||||
|
|
||||||
chain = []
|
chain = []
|
||||||
engines = _engine_list(using)
|
engines = _engine_list(using)
|
||||||
for template_name in template_name_list:
|
for template_name in template_name_list:
|
||||||
|
@ -60,6 +60,15 @@ class TemplateLoaderTests(SimpleTestCase):
|
|||||||
with self.assertRaises(TemplateDoesNotExist):
|
with self.assertRaises(TemplateDoesNotExist):
|
||||||
select_template([])
|
select_template([])
|
||||||
|
|
||||||
|
def test_select_template_string(self):
|
||||||
|
with self.assertRaisesMessage(
|
||||||
|
TypeError,
|
||||||
|
"select_template() takes an iterable of template names but got a "
|
||||||
|
"string: 'template_loader/hello.html'. Use get_template() if you "
|
||||||
|
"want to load a single template by name."
|
||||||
|
):
|
||||||
|
select_template('template_loader/hello.html')
|
||||||
|
|
||||||
def test_select_template_not_found(self):
|
def test_select_template_not_found(self):
|
||||||
with self.assertRaises(TemplateDoesNotExist) as e:
|
with self.assertRaises(TemplateDoesNotExist) as e:
|
||||||
select_template(["template_loader/unknown.html",
|
select_template(["template_loader/unknown.html",
|
||||||
|
Loading…
Reference in New Issue
Block a user