{"id":253,"hash":"f114f7908fddb98e9e355de2cbbc613cb7bfa1d4f4f939fc3860a5921b62e450","pattern":"Flask raises TemplateNotFound error even though template file exists","full_message":"I am trying to render the file home.html.  The file exists in my project, but I keep getting jinja2.exceptions.TemplateNotFound: home.html when I try to render it.  Why can't Flask find my template?\n\nfrom flask import Flask, render_template\n\napp = Flask(__name__)\n\n@app.route('/')\ndef home():\n    return render_template('home.html')\n\n/myproject\n    app.py\n    home.html","ecosystem":"pypi","package_name":"file","package_version":null,"solution":"You must create your template files in the correct location; in the templates subdirectory next to the python module (== the module where you create your Flask app).\n\nThe error indicates that there is no home.html file in the templates/ directory. Make sure you created that directory in the same directory as your python module, and that you did in fact put a home.html file in that subdirectory.  If your app is a package, the templates folder should be created inside the package.\n\nmyproject/\n    app.py\n    templates/\n        home.html\n\nmyproject/\n    mypackage/\n        __init__.py\n        templates/\n            home.html\n\nAlternatively, if you named your templates folder something other than templates and don't want to rename it to the default, you can tell Flask to use that other directory.\n\napp = Flask(__name__, template_folder='template')  # still relative to module\n\nYou can ask Flask to explain how it tried to find a given template, by setting the EXPLAIN_TEMPLATE_LOADING option to True. For every template loaded, you'll get a report logged to the Flask app.logger, at level INFO.\n\nThis is what it looks like when a search is successful; in this example the foo/bar.html template extends the base.html template, so there are two searches:\n\n[2019-06-15 16:03:39,197] INFO in debughelpers: Locating template \"foo/bar.html\":\n    1: trying loader of application \"flaskpackagename\"\n       class: jinja2.loaders.FileSystemLoader\n       encoding: 'utf-8'\n       followlinks: False\n       searchpath:\n         - /.../project/flaskpackagename/templates\n       -> found ('/.../project/flaskpackagename/templates/foo/bar.html')\n[2019-06-15 16:03:39,203] INFO in debughelpers: Locating template \"base.html\":\n    1: trying loader of application \"flaskpackagename\"\n       class: jinja2.loaders.FileSystemLoader\n       encoding: 'utf-8'\n       followlinks: False\n       searchpath:\n         - /.../project/flaskpackagename/templates\n       -> found ('/.../project/flaskpackagename/templates/base.html')\n\nBlueprints can register their own template directories too, but this is not a requirement if you are using blueprints to make it easier to split a larger project across logical units. The main Flask app template directory is always searched first even when using additional paths per blueprint.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/23327293/flask-raises-templatenotfound-error-even-though-template-file-exists","votes":258,"created_at":"2026-04-19T04:41:39.770551+00:00","updated_at":"2026-04-19T04:51:51.424009+00:00"}