Where to place template-files for frappe.render_template()?

Hello,
I’m calling

frappe.render_template("templates/my_template.html", {"emp": employee, "schluessel" : schluessel})

from file

~frappe-bench/apps/erpituc/erpituc/erpituc/doctype/schluessel/api.py

I’m getting the error

  File "/home/frappe/frappe-bench/env/lib/python3.7/site-packages/jinja2/loaders.py", line 429, in load
    raise TemplateNotFound(name)
jinja2.exceptions.TemplateNotFound: templates/my_template.html

The file exists in these locations:

  • ~/frappe-bench/apps/erpituc/erpituc/erpituc/doctype/schluessel/templates/my_template.html
  • ~/frappe-bench/sites/assets/templates/my_template.html
  • ~frappe-bench/sites/erpnextthkr.schloss.ituc.de/private/templates/my_template.html
  • ~frappe-bench/sites/erpnextthkr.schloss.ituc.de/public/templates/my_template.html

Bench was restarted.

It’s obvious that I didn’t specify the right path to my template. What’s not so obvious is where to place my_template.html so it can be found by render_template().

Does anyone knows the right way to do this?

1 Like

Well, you can always put the HTML of the Template in a “Print Format” and access it by doing

html = frappe.db.get_value("Print Format", "My Print Format", "html")
frappe.render_template(html, {"employee": employee})

By this you can even edit it directly in ERPNext.

Wow, thank you thkr for this amazing workaround. I wonder what other suggestions we will see.

This should work as well:

frappe.render_template("erpituc/erpituc/doctype/schluessel/templates/my_template.html", {"emp": employee, "schluessel" : schluessel})
1 Like

And it does! Thanks for helping me out.