I created two file: one, main.py and the other, default.j2. When I run cmd from the folder "code" where both are located (main.py and default.j2,) it works fine, but I try to automate the script on Windows Task Scheduler, it displays "No template file present: default.j2" even though the template exists in the path/folder.
Below is the code I use to check to whether the path is found or not.
def render_template(template, **kwargs):
# check if template exists
if not os.path.exists(template):
print('No template file present: %s' % template)
sys.exit()
import jinja2
templateLoader = jinja2.FileSystemLoader(searchpath="")
templateEnv = jinja2.Environment(loader=templateLoader)
templ = templateEnv.get_template(template)
return templ.render(**kwargs)