﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20995	{% include %} uses get_template where it could select_template	Keryn Knight <django@…>	KESHAV KUMAR	"It'd be nice if the Include template tag was sensible enough to allow fallbacks by selecting the most appropriate template, as things like `render`/`render_to_response`/`render_to_string` do. It's tripped me up on more than one occasion, and it seems a trivial feature to support, from my limited testing.
{{{
>>> from django.template import Template, Context
>>> tmpl = Template('{% include var %}')
>>> ctx = Context({'var':'admin/base.html'})
>>> ctx
[{'var': 'admin/base.html'}]
>>> tmpl.render(ctx)
... some HTML output ...
>>> ctx.update({'var':['admin/base.html', 'admin/fail.html']})
{'var': ['admin/base.html', 'admin/fail.html']}
>>> tmpl.render(ctx)
Traceback (most recent call last):
  File ""<console>"", line 1, in <module>
  File ""/path/django/template/base.py"", line 140, in render
    return self._render(context)
  File ""/path/django/template/base.py"", line 134, in _render
    return self.nodelist.render(context)
  File ""/path/django/template/base.py"", line 823, in render
    bit = self.render_node(node, context)
  File ""/path/django/template/debug.py"", line 74, in render_node
    return node.render(context)
  File ""/path/django/template/loader_tags.py"", line 165, in render
    template = get_template(template_name)
  File ""/path/django/template/loader.py"", line 145, in get_template
    template, origin = find_template(template_name)
  File ""/path/django/template/loader.py"", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: ['admin/base.html', 'admin/fail.html']
}}}

The 'fix' is to change [https://github.com/django/django/blob/5cdacbda034af928f5033c9afc7b50ee0b13f75c/django/template/loader_tags.py#L166 this line] from `get_template` to `select_template`, though this might now be slightly complicated by the recent changes in 5cdacbda034af928f5033c9afc7b50ee0b13f75c to allow for rendering of `Template` instances.

Changing to `select_template` on 1.4 yields the results I'd expect:
{{{
>>> from django.template import Template, Context 
>>> tmpl = Template('{% include var %}')
>>> ctx = Context({'var':['admin/base.html', 'admin/fail.html']})
>>> tmpl.render(ctx)
... some HTML output ...
}}}

Both the above shell sessions assume `django.contrib.admin` is in INSTALLED_APPS.
"	New feature	closed	Template system	dev	Normal	fixed			Accepted	1	0	0	0	0	0
