diff --git a/CHANGES b/CHANGES index 9e41733e..15104100 100644 --- a/CHANGES +++ b/CHANGES @@ -44,6 +44,9 @@ Version 1.0 - Added the ``EXPLAIN_TEMPLATE_LOADING`` config flag which when enabled will instruct Flask to explain how it locates templates. This should help users debug when the wrong templates are loaded. +- Enforce blueprint handling in the order they were registered for template + loading. + Version 0.10.2 -------------- diff --git a/flask/app.py b/flask/app.py index f287d684..2840f426 100644 --- a/flask/app.py +++ b/flask/app.py @@ -472,6 +472,7 @@ class Flask(_PackageBoundObject): #: #: .. versionadded:: 0.7 self.blueprints = {} + self._blueprint_order = [] #: a place where extensions can store application specific state. For #: example this is where an extension could store database engines and @@ -903,9 +904,17 @@ class Flask(_PackageBoundObject): (blueprint, self.blueprints[blueprint.name], blueprint.name) else: self.blueprints[blueprint.name] = blueprint + self._blueprint_order.append(blueprint) first_registration = True blueprint.register(self, options, first_registration) + def iter_blueprints(self): + """Iterates over all blueprints by the order they were registered. + + .. versionadded:: 1.0 + """ + return iter(self._blueprint_order) + @setupmethod def add_url_rule(self, rule, endpoint=None, view_func=None, **options): """Connects a URL rule. Works exactly like the :meth:`route` diff --git a/flask/templating.py b/flask/templating.py index 01ae7203..9334e0d6 100644 --- a/flask/templating.py +++ b/flask/templating.py @@ -13,7 +13,6 @@ from jinja2 import BaseLoader, Environment as BaseEnvironment, \ from .globals import _request_ctx_stack, _app_ctx_stack from .signals import template_rendered -from ._compat import itervalues, iteritems def _default_template_ctx_processor(): @@ -81,7 +80,7 @@ class DispatchingJinjaLoader(BaseLoader): if loader is not None: yield self.app, loader - for blueprint in itervalues(self.app.blueprints): + for blueprint in self.app.iter_blueprints(): loader = blueprint.jinja_loader if loader is not None: yield blueprint, loader @@ -92,7 +91,7 @@ class DispatchingJinjaLoader(BaseLoader): if loader is not None: result.update(loader.list_templates()) - for name, blueprint in iteritems(self.app.blueprints): + for blueprint in self.app.iter_blueprints(): loader = blueprint.jinja_loader if loader is not None: for template in loader.list_templates():