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
Provenance
- Commit
0a93c55- Tree
de20929- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
596ae0c
3 files changed+26 added−11 removed
modified:flask/templating.py+12 added-10 removed
32 unmodified lines33 def __init__(self, app):34 self.app = app35 36 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)54 55 def list_templates(self):56 result = self.app.jinja_loader.list_templates()57 for name, module in self.app.modules.iteritems():31 unmodified linesmodified:tests/flask_tests.py+12 added
19 unmodified lines20 from contextlib import contextmanager21 from datetime import datetime22 from werkzeug import parse_date, parse_options_header23 from werkzeug.exceptions import NotFound24+from jinja2 import TemplateNotFound25 from cStringIO import StringIO26 27 example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')28 sys.path.append(os.path.join(example_path, 'flaskr'))633 unmodified lines662 with app.test_request_context():663 assert flask.url_for('admin.static', filename='test.txt') \664 == '/admin/static/test.txt'665 666+ 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'673+674+ with flask.Flask(__name__).test_request_context():675+ assert flask.render_template('nested/nested.txt') == 'I\'m nested'676+677 def test_safe_access(self):678 from moduleapp import app679 680 with app.test_request_context():280 unmodified linesmodified:CHANGES+2 added-1 removed
6 unmodified lines7 -------------8 9 Bugfix Release, released on July 6th 201010 11-- fixes an issue with template loading for modules11+- fixes an issue with template loading from directories when modules12+ where used.13 14 15 Version 0.516 -----------91 unmodified lines