Frappe.render_template custom template folder

When I want to use frappe.render_template for my custom html template,

                with open(model_path, 'wb') as f:
                    f.write(frappe.render_template("templates/autodoc/my_html.html",
                                                   self.app_context, is_path=True).encode('utf-8'))

I receive:

jinja2.exceptions.TemplateNotFound: templates/autodoc/my_html.html

If I give full path to this folder, I receive the same error:

jinja2.exceptions.TemplateNotFound: /home/emil/Desktop/frappe-bench/apps/{*name_of_app*}/{*name_of_app*}/templates/autodoc/my_html.html

My templates folder contain by path:
/home/emil/Desktop/frappe-bench/apps/{*name_of_app*}/{*name_of_app*}/templates

Which problems can be? How I can directly point the template directory for render_template function?

I have same question!
did you find any helpful reference?

Hello!
I wrote function, that can do the same logic for it.

    def render_autodoc(self, template, doc_path, context=None):
        """ Render doc from templates folder """
        if context:
            context.update(self.app_context)
        else:
            context = self.app_context
        with open(os.path.join(self.autodoc_path, template), 'r') as f:
            content = frappe.render_template(f.read(), context=context)
        with open(doc_path, 'w') as f:
            f.write(content)

It is very useful, that render_template can accept string with raw_html code as parameter

1 Like