0

I am following this tutorial . Similar to Flask raises TemplateNotFound error even though template file exists from six years ago, I cannot render the page because Flask raises "jinja2.exceptions.TemplateNotFound: hello_there.html". Not only is hello_there.html in the templates directory, I believe templates is located in the right place because it's in the same directory as the Python module (outside the virtual environment):

hello_flask/
    env/
        app.py
    templates/
        hello_there.html

From that same post, I tried setting the EXPLAIN_TEMPLATE_LOADING option to True, but I didn't get a report logged to the Flask app.logger if I configured it correctly in launch.json:

"env": {
            "FLASK_APP": "app.py",
            "FLASK_ENV": "development",
            "EXPLAIN_TEMPLATE_LOADING": "True",
            "FLASK_DEBUG": "0"
        }

Okay, finally, when I run the program through the Flask debug configuration, it raises FileNotFoundError, "The system cannot find the path specified". Would this affect the template error? I have run a basic python Flask file fine without templates even with this error. I've tried to fix it by adding the location of the interpret to the PATH variable which I copied from a sys.executable print statement, but the interpreter still raises it.

Wisely
  • 51
  • 2
  • 5
  • `app.py` should not be in the `env` directory. Move it in the upper directory next to `templates`. – Victor Jan 17 '21 at 03:29

1 Answers1

0

Keep the app.py file and templates folder in the same directory. Also you can explicitly mention the templates folder name.

In your app.py;

app = Flask(__name__, template_folder='templates')
Irfan wani
  • 4,084
  • 2
  • 19
  • 34