Framework Error
TemplateNotFound: 'base.html' template not found in the templates directory
What This Error Means
This error occurs when a templating engine, such as Jinja2, is unable to locate a template file.
Why It Happens
This error typically happens when the template file name is misspelled, the file is not in the expected location, or the directory is not being scanned for templates correctly.
How to Fix It
- 1To fix this error, ensure the template file exists in the correct location and is named exactly as specified in the code. If the file is in a subdirectory, make sure the directory is being scanned for templates. You can also use the 'auto_reload' feature in Flask to automatically reload templates when changes are made.
Example Code Solution
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('non_existent_template.html')from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('base.html') # Correct template file nameFix for TemplateNotFound: 'base.html' template not found in the templates directory
Browse Related Clusters
Related PYTHON Errors
RuntimeError: Cannot schedule new futures after shutdown
CursorError: LastError: (1062, "Duplicate entry 'user123' for key 'use
OperationalError: (1048, "Column 'username' cannot be null")
CursorError: unsupported database type: 'sqlite3': 'DBM' mode not supp
Related PYTHON Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error