I have the following project,
APP
|-static
|-templates
|-file.html
|-blueprints
|-blueprint1.py
|-blueprint2.py
|-app.py
Each blueprint file has various sanic
routes that I want to render a template when called.
I have tried putting the following in each blueprint
file,
template_env = Environment(
loader=PackageLoader('APP', 'static/templates'),
autoescape=select_autoescape(['html', 'xml'])
)
only to get the error ModuleNotFoundError: No module named 'APP'
Substituting APP
with blueprints
gives me the error TypeError: expected str, bytes or os.PathLike object, not NoneType
I have also tried using a FileSystemLoader
like this,
template_loader = FileSystemLoader(searchpath="../static/templates")
template_env = Environment(loader=template_loader)
and load the template I need template = template_env.get_template('file.html')
But I get a template not found
when visiting the url.
Directly trying to render my template with,
with open('..static/templates/file.html') as file:
template = Template(file.read())
again results in a file not found
error.
What is the best way to use jinja
templates in my app?