TemplateNotFound: index.html
TemplateNotFound: index.html
$ flask run
Traceback (most recent call last):
...
jinja2.exceptions.TemplateNotFound: index.html
Why this happens
Flask searches for templates in the templates/ folder relative to the application or blueprint. Wrong filenames, missing directories, or custom template_folder misconfigurations cause this error.
Fix
- Create a
templates/directory and placeindex.htmlinside. - If using blueprints, ensure their
template_folderis correctly set or use absolute paths.
Wrong code
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.htm") # wrong filename
Fixed code
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")