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
MemoryError: Unable to allocate 1000 bytes for an array with shape (10
Failed to resolve route for URL '/admin/dashboard'. The route 'admin_d
CursorError: unsupported database type: 'sqlite3': 'DBM' mode not supp
RuntimeError: cannot pickle local function '<locals>.<lambda>'
Related PYTHON Blog Articles
Have a different error? Get an instant explanation.
Explain Another Error