Loading django/template/loader_tags.py +5 −2 Original line number Diff line number Diff line Loading @@ -159,8 +159,11 @@ class IncludeNode(BaseIncludeNode): def render(self, context): try: template_name = self.template_name.resolve(context) template = get_template(template_name) template = self.template_name.resolve(context) # Does this quack like a Template? if not callable(getattr(template, 'render', None)): # If not, we'll try get_template template = get_template(template) return self.render_template(template, context) except: if settings.TEMPLATE_DEBUG: Loading docs/ref/templates/builtins.txt +6 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,12 @@ the variable ``template_name``:: {% include template_name %} .. versionchanged:: 1.7 The variable may also be any object with a ``render()`` method that accepts a context. This allows you to reference a compiled ``Template`` in your context. An included template is rendered with the context of the template that's including it. This example produces the output ``"Hello, John"``: Loading docs/releases/1.7.txt +5 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,11 @@ Templates * The :ttag:`widthratio` template tag now accepts an "as" parameter to capture the result in a variable. * The :ttag:`include` template tag will now also accept anything with a ``render()`` method (such as a ``Template``) as an argument. String arguments will be looked up using :func:`~django.template.loader.get_template` as always. Backwards incompatible changes in 1.7 ===================================== Loading tests/template_tests/tests.py +11 −0 Original line number Diff line number Diff line Loading @@ -338,6 +338,17 @@ class TemplateLoaderTests(TestCase): loader.template_source_loaders = old_loaders settings.TEMPLATE_DEBUG = old_td def test_include_template_argument(self): """ Support any render() supporting object """ ctx = Context({ 'tmpl': Template('This worked!'), }) outer_tmpl = Template('{% include tmpl %}') output = outer_tmpl.render(ctx) self.assertEqual(output, 'This worked!') class TemplateRegressionTests(TestCase): Loading Loading
django/template/loader_tags.py +5 −2 Original line number Diff line number Diff line Loading @@ -159,8 +159,11 @@ class IncludeNode(BaseIncludeNode): def render(self, context): try: template_name = self.template_name.resolve(context) template = get_template(template_name) template = self.template_name.resolve(context) # Does this quack like a Template? if not callable(getattr(template, 'render', None)): # If not, we'll try get_template template = get_template(template) return self.render_template(template, context) except: if settings.TEMPLATE_DEBUG: Loading
docs/ref/templates/builtins.txt +6 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,12 @@ the variable ``template_name``:: {% include template_name %} .. versionchanged:: 1.7 The variable may also be any object with a ``render()`` method that accepts a context. This allows you to reference a compiled ``Template`` in your context. An included template is rendered with the context of the template that's including it. This example produces the output ``"Hello, John"``: Loading
docs/releases/1.7.txt +5 −0 Original line number Diff line number Diff line Loading @@ -258,6 +258,11 @@ Templates * The :ttag:`widthratio` template tag now accepts an "as" parameter to capture the result in a variable. * The :ttag:`include` template tag will now also accept anything with a ``render()`` method (such as a ``Template``) as an argument. String arguments will be looked up using :func:`~django.template.loader.get_template` as always. Backwards incompatible changes in 1.7 ===================================== Loading
tests/template_tests/tests.py +11 −0 Original line number Diff line number Diff line Loading @@ -338,6 +338,17 @@ class TemplateLoaderTests(TestCase): loader.template_source_loaders = old_loaders settings.TEMPLATE_DEBUG = old_td def test_include_template_argument(self): """ Support any render() supporting object """ ctx = Context({ 'tmpl': Template('This worked!'), }) outer_tmpl = Template('{% include tmpl %}') output = outer_tmpl.render(ctx) self.assertEqual(output, 'This worked!') class TemplateRegressionTests(TestCase): Loading