["python","templates","jinja2"]
How to load jinja template directly from filesystem

The jinja API document at pocoo.org states: The simplest way to configure Jinja2 to load templates for your application looks roughly like this: from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('yourapplication', templates')) This will create a template environment with the default settings and a loader that looks up the templates in the templates folder inside the yourapplication python package. As it turns out, this isn't so simple because you have to make/install a python package with your templates in it, which introduces a lot of needless complexity, especially if you have no intention of distributing your code. I found these related questions about doing so, but the answers are vague and unsatisfying: need to package jinja2 template for python How to make a python package containing only jinja templates How can I load the template directly from the filesystem, not as a resource in a package?
Use a FileSystemLoader instead of a PackageLoader. Suppose there is a python file in the same directory as the template: ./index.py ./template.html This index.py will find the template and render it: #!/usr/bin/python import jinja2 templateLoader = jinja2.FileSystemLoader(searchpath="./") templateEnv = jinja2.Environment(loader=templateLoader) TEMPLATE_FILE = "template.html" template = templateEnv.get_template(TEMPLATE_FILE) outputText = template.render() # this is where to put args to the template renderer print(outputText) In the introduction, the PackageLoader approach seems to be presented as the default, "simplest" method; however, there is also a section which discusses all the built-in loaders.