Jinja2 cannot read a template file with a particular full path

45 views Asked by At

Normally, jinja2 render_template method asks a string of a full path of html. I do as the format below but it still raise the error.

render_template('/var/www/xyz/template/_base_front.html', {"data":"pc"})

I try opening the path by using nano editor, it works fine. A particular file is full permission of read, write, and execute. A screenshot

1

There are 1 answers

0
ilias-sp On BEST ANSWER

you need to place the file in the templates folder (default folder if you didn't define your own template_folder) and provide a relative path to it (probably _base_front.html in your case).

from documentation:

To render a template you can use the render_template() method. All you have to do is provide the name of the template and the variables you want to pass to the template engine as keyword arguments. Here’s a simple example of how to render a template:

Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package: