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.
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:
Blueprints
is subsequently to class _PackageBoundObject
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With