How to load from more then one template_folder for Flask blueprint?
blueprint, flask, jinja2, python
Solution
Here is the trail of investigations.
From flask.blueprints
class Blueprint(_PackageBoundObject):
....
def __init__(self, name, import_name, static_folder=None,
static_url_path=None, template_folder=None,
...)
_PackageBoundObject.__init__(self, import_name, template_folder)
....
From flask.helpers
@locked_cached_property
def jinja_loader(self):
"""The Jinja loader for this package bound object.
.. versionadded:: 0.5
"""
if self.template_folder is not None:
return FileSystemLoader(os.path.join(self.root_path,
self.template_folder))
Investigation Result:
- template_folder which is passed to `Blueprints` is subsequently to class `_PackageBoundObject`
- It is treated as a single string and not as a list of folders
Result:
- You can not pass multiple paths for template_folder
Problem
I learned how to create Flask Blueprints and can create blueprint for non flask products that uses Jinja2 templates and use them inside flask projects. I do something like this: ``` # blueprint code from flask import Blueprint from pkg_resources import resource_filename app = Blueprint('formgear', __name__, template_folder=resource_filename('formgear', 'templates')) ``` And now I want to add another set of templates, which is logically connected with my non-Flask project but are Flask-only specific. I'm completely not sure is it good desing, but is there any way to propagate both templates folders from one blueprint? And make both templates set available for whole Flask project? Note: `formgear` is name of my non-Flask project.