Framework Error
TemplateNotFound: The template 'base.html' was not found in the templates directory
What This Error Means
This error occurs when Flask is unable to locate a specified template. It is usually caused by a typo in the template name or a missing template file.
Why It Happens
Flask's Jinja2 templating engine throws this error when it cannot find a specified template file. This can happen if the template file is misspelled, deleted, or not correctly registered with the application.
How to Fix It
- 1To resolve this error, ensure that the template file exists in the templates directory and the name is spelled correctly. If the template is in a subdirectory, make sure to include the directory path in the template name. Alternatively, you can register the template using the `render_template_string()` method if you need to render a template from a string.
Example Code Solution
from flask import Flask, render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def index():
return render_template('base.html')from flask import Flask, render_template
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.route('/')
def index():
return render_template('templates/base.html') # Include the directory pathFix for TemplateNotFound: The template 'base.html' was 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