Skip to content
Myr

Allow loading template from iterable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dmitry Shevchenko · committed by Dmitry Shevchenko · parent 04bb720 · Browse files · 2 files+24 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−3 removed

  • other:+24 added−3 removed

2 files+24 added−3 removed

modified:flask/testsuite/templating.py+19 added
176 unmodified lines
177 rv = c.get('/')178 self.assert_equal(rv.data, 'Hello Custom World!')179180181 def test_iterable_loader(self):182 app = flask.Flask(__name__)183 @app.context_processor184 def context_processor():185 return {'whiskey': 'Jameson'}186 @app.route('/')187 def index():188 return flask.render_template(189 ['no_template.xml', # should skip this one190 'simple_template.html', # should render this191 'context_template.html'],192 value=23)193194 rv = app.test_client().get('/')195 self.assert_equal(rv.data, '<h1>Jameson</h1>')196197198199200def suite():201 suite = unittest.TestSuite()202 suite.addTest(unittest.makeSuite(TemplatingTestCase))203 return suite
modified:flask/templating.py+5 added-3 removed
107 unmodified lines
108 template_rendered.send(app, template=template, context=context)109 return rv110111112def render_template(template_name, **context):112def render_template(template_name_or_list, **context):113 """Renders a template from the template folder with the given114 context.115116 :param template_name: the name of the template to be rendered116 :param template_name_or_list: the name of the template to be117 rendered, or an iterable with template names118 the first one existing will be rendered119 :param context: the variables that should be available in the120 context of the template.121 """122 ctx = _request_ctx_stack.top123 ctx.app.update_template_context(context)122 return _render(ctx.app.jinja_env.get_template(template_name),124 return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),125 context, ctx.app)126127128def render_template_string(source, **context):
12 unmodified lines