Browse Source

Fixed a template lookup error

pull/112/head
Armin Ronacher 15 years ago
parent
commit
0a93c552cc
  1. 3
      CHANGES
  2. 22
      flask/templating.py
  3. 12
      tests/flask_tests.py

3
CHANGES

@ -8,7 +8,8 @@ Version 0.5.1
Bugfix Release, released on July 6th 2010
- fixes an issue with template loading for modules
- fixes an issue with template loading from directories when modules
where used.
Version 0.5

22
flask/templating.py

@ -34,21 +34,23 @@ class _DispatchingJinjaLoader(BaseLoader):
self.app = app
def get_source(self, environment, template):
name = template
loader = None
try:
module, name = template.split('/', 1)
loader = self.app.modules[module].jinja_loader
if loader is None:
raise ValueError()
except (ValueError, KeyError):
pass
if loader is None:
loader = self.app.jinja_loader
try:
return loader.get_source(environment, name)
except TemplateNotFound:
# re-raise the exception with the correct fileame here.
# (the one that includes the prefix)
raise TemplateNotFound(template)
if loader is not None:
return loader.get_source(environment, template)
else:
try:
return loader.get_source(environment, name)
except TemplateNotFound:
pass
# raise the exception with the correct fileame here.
# (the one that includes the prefix)
raise TemplateNotFound(template)
def list_templates(self):
result = self.app.jinja_loader.list_templates()

12
tests/flask_tests.py

@ -21,6 +21,7 @@ from contextlib import contextmanager
from datetime import datetime
from werkzeug import parse_date, parse_options_header
from werkzeug.exceptions import NotFound
from jinja2 import TemplateNotFound
from cStringIO import StringIO
example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
@ -662,6 +663,17 @@ class ModuleTestCase(unittest.TestCase):
assert flask.url_for('admin.static', filename='test.txt') \
== '/admin/static/test.txt'
with app.test_request_context():
try:
flask.render_template('missing.html')
except TemplateNotFound, e:
assert e.name == 'missing.html'
else:
assert 0, 'expected exception'
with flask.Flask(__name__).test_request_context():
assert flask.render_template('nested/nested.txt') == 'I\'m nested'
def test_safe_access(self):
from moduleapp import app

Loading…
Cancel
Save