Skip to content
Myr

Fixed a template lookup error

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 596ae0c · Browse files · 3 files+26 added−11 removed
This commit

State

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

Diff stats

3 files+26 added−11 removed

  • tests:+12 added−0 removed
  • other:+14 added−11 removed

3 files+26 added−11 removed

modified:flask/templating.py+12 added-10 removed
32 unmodified lines
33 def __init__(self, app):34 self.app = app3536 def get_source(self, environment, template):37 name = template38 loader = None37 try:38 module, name = template.split('/', 1)39 loader = self.app.modules[module].jinja_loader40 if loader is None:41 raise ValueError()42 except (ValueError, KeyError):43 pass44 if loader is None:43 loader = self.app.jinja_loader46 try:47 return loader.get_source(environment, name)48 except TemplateNotFound:49 # re-raise the exception with the correct fileame here.50 # (the one that includes the prefix)51 raise TemplateNotFound(template)44 if loader is not None:45 return loader.get_source(environment, template)46 else:47 try:48 return loader.get_source(environment, name)49 except TemplateNotFound:50 pass51 # raise the exception with the correct fileame here.52 # (the one that includes the prefix)53 raise TemplateNotFound(template)5455 def list_templates(self):56 result = self.app.jinja_loader.list_templates()57 for name, module in self.app.modules.iteritems():
31 unmodified lines
modified:tests/flask_tests.py+12 added
19 unmodified lines
20from contextlib import contextmanager21from datetime import datetime22from werkzeug import parse_date, parse_options_header23from werkzeug.exceptions import NotFound24from jinja2 import TemplateNotFound25from cStringIO import StringIO2627example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')28sys.path.append(os.path.join(example_path, 'flaskr'))
633 unmodified lines
662 with app.test_request_context():663 assert flask.url_for('admin.static', filename='test.txt') \664 == '/admin/static/test.txt'665666 with app.test_request_context():667 try:668 flask.render_template('missing.html')669 except TemplateNotFound, e:670 assert e.name == 'missing.html'671 else:672 assert 0, 'expected exception'673674 with flask.Flask(__name__).test_request_context():675 assert flask.render_template('nested/nested.txt') == 'I\'m nested'676677 def test_safe_access(self):678 from moduleapp import app679680 with app.test_request_context():
280 unmodified lines
modified:CHANGES+2 added-1 removed
6 unmodified lines
7-------------89Bugfix Release, released on July 6th 20101011- fixes an issue with template loading for modules11- fixes an issue with template loading from directories when modules12 where used.131415Version 0.516-----------
91 unmodified lines