Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added create_jinja_loader

  • Loading branch information...
commit 00c5b7a937b63378394fc6fc576aa6c27106d6d6 1 parent b49de85
@mitsuhiko authored
Showing with 23 additions and 1 deletion.
  1. +1 −0  CHANGES
  2. +9 −1 flask/app.py
  3. +13 −0 tests/flask_tests.py
View
1  CHANGES
@@ -35,6 +35,7 @@ Release date to be announced, codename to be selected
a decorator.
- Use Last-Modified for static file sending instead of Date which
was incorrectly introduced in 0.6.
+- Added `create_jinja_loader` to override the loader creation process.
Version 0.6.1
-------------
View
10 flask/app.py
@@ -352,7 +352,15 @@ def create_jinja_environment(self):
options = dict(self.jinja_options)
if 'autoescape' not in options:
options['autoescape'] = self.select_jinja_autoescape
- return Environment(loader=_DispatchingJinjaLoader(self), **options)
+ return Environment(loader=self.create_jinja_loader(), **options)
+
+ def create_jinja_loader(self):
+ """Creates the loader for the Jinja2 environment. Can be used to
+ override just the loader and keeping the rest unchanged.
+
+ .. versionadded:: 0.7
+ """
+ return _DispatchingJinjaLoader(self)
def init_jinja_globals(self):
"""Called directly after the environment was created to inject
View
13 tests/flask_tests.py
@@ -857,6 +857,19 @@ def index():
rv = app.test_client().get('/')
assert rv.data == 'dcba'
+ def test_custom_template_loader(self):
+ class MyFlask(flask.Flask):
+ def create_jinja_loader(self):
+ from jinja2 import DictLoader
+ return DictLoader({'index.html': 'Hello Custom World!'})
+ app = MyFlask(__name__)
+ @app.route('/')
+ def index():
+ return flask.render_template('index.html')
+ c = app.test_client()
+ rv = c.get('/')
+ assert rv.data == 'Hello Custom World!'
+
class ModuleTestCase(unittest.TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.