jinja2.exceptions.templatenotfound: base.html

app = Flask(__name__, template_folder={path of template directory})

4
2
Phoenix Logan 186120 points

                                    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).

The 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.

myproject/
    app.py
    templates/
        home.html
myproject/
    mypackage/
        __init__.py
        templates/
            home.html
Alternatively, 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.

app = Flask(__name__, template_folder='template')  # still relative to module
You 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.

This 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:

[2019-06-15 16:03:39,197] INFO in debughelpers: Locating template "foo/bar.html":
    1: trying loader of application "flaskpackagename"
       class: jinja2.loaders.FileSystemLoader
       encoding: 'utf-8'
       followlinks: False
       searchpath:
         - /.../project/flaskpackagename/templates
       -> found ('/.../project/flaskpackagename/templates/foo/bar.html')
[2019-06-15 16:03:39,203] INFO in debughelpers: Locating template "base.html":
    1: trying loader of application "flaskpackagename"
       class: jinja2.loaders.FileSystemLoader
       encoding: 'utf-8'
       followlinks: False
       searchpath:
         - /.../project/flaskpackagename/templates
       -> found ('/.../project/flaskpackagename/templates/base.html')
Blueprints 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.

4 (2 Votes)
0
3.75
4
Awgiedawgie 440220 points

                                    from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('home.html')

3.75 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
jinja2.exceptions.TemplateNotFound: test1.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: /test.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: quiz.html jinja2.exceptions.TemplateNotFound: welcome.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: layout.html jinja2.exceptions.TemplateNotFound: view.html jinja2.exceptions.TemplateNotFound: page.html jinja2.exceptions.TemplateNotFound: page.html jinja2.exceptions.TemplateNotFound: bootstrap/base.html jinja2.exceptions.TemplateNotFound: apps/templates/dashboard.html jinja2.exceptions.TemplateNotFound: index.html\ raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: Login.html jinja2.exceptions.TemplateNotFound extends jinja2.exceptions.TemplateNotFound: .index.html jinja2.exceptions.TemplateNotFound: test.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: index.html jinja2.exceptions.TemplateNotFound: index.html.j2 jinja2.exceptions.TemplateNotFound: base.html jinja2.exceptions.TemplateNotFound: Homepage.html jinja2.exceptions.templatenotfound home.html jinja2.exceptions.TemplateNotFound: site.html jinja2.exceptions.TemplateNotFound: page1.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: template/index.html 127.0.0.1 - - [25/Jun/2021 16:39:45] "GET / HTTP/1.1" 500 - jinja2.exceptions.TemplateNotFound: about.html jinja2.exceptions.TemplateNotFound: E:\P_MYWORK\home.html jinja2.exceptions.TemplateNotFound: / jinja2.exceptions.TemplateNotF jinja2.exceptions.TemplateNotFound: html.tpl jinja2.exceptions.TemplateNotFound: memes.html jinja2.exceptions.TemplateNotFound: get_memes.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: base.html jinja2.exceptions.TemplateNotFound: insertStudent.html jinja2.exceptions.TemplateNotFound: ./index.html jinja2.exceptions .templatenotfound jinja2.exceptions.TemplateNotFound: abc.html jinja2.exceptions.TemplateNotFound: download.html jinja2.exceptions.TemplateNotFound: ../templates/index.html jinja2.exceptions.TemplateNotFound: /login raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: basic.html.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: final.html jinja2.exceptions.TemplateNotFound: browser-open.html flask error jinja2.exceptions.TemplateNotFound jinja2 exceptions templatenotfound TemplateNotFound(template)jinja2.exceptions.TemplateNotFound flask jinja2.exceptions.TemplateNotFound: jinja2.exceptions.TemplateNotFound: 500.html flask jinja2.exceptions.templatenotfound flask render_template jinja2.exceptions.TemplateNotFound: item.html jinja2.exceptions.TemplateNotFound: register.html jinja2.exceptions.templatenotfound index.html docker jinja2.exceptions.TemplateNotFound: result.html jinja2.exceptions.TemplateNotFound: /template/index.html 127.0.0.1 - - [07/May/2021 18:43:14] "GET / HTTP/1.1" 500 - jinja2.exceptions.TemplateNotFound: ../templates/home.html !mdn jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: home.html jinja2.exceptions.TemplateNotFound in Flask flask raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: home.html jinja2.exceptions.TemplateNotFound how to handle this error jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: form.html jinja2.exceptions.TemplateNotFound: layout.htm jinja2.exceptions.TemplateNotFound: upload.html jinja2.exceptions.TemplateNotFound: ../static/js/main.js uWSGI: jinja2.exceptions.TemplateNotFound: index.html jinja2.exceptions.TemplateNotFound. jinja2.exceptions.TemplateNotFound flask jinja2.exceptions.TemplateNotFound: contact.html jinja2.exceptions.TemplateNotFound: p.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: index.html jinja2.exceptions.TemplateNotFound: sau.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: template/index.html jinja2.exceptions.TemplateNotFound: ./home.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: Home.html how to solve jinja2.exceptions.templatenotfound error python jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: login.html jinja2.exceptions.TemplateNotFound: application/templates/index.html jinja2.exceptions.TemplateNotFound: home.html jinja2.exceptions.templatenotfound hello.html aise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: base.html TemplateNotFound(template) jinja2.exceptions.TemplateNotFound jinja2.exceptions.templatenotfound index.html jinja2.exceptions.TemplateNotFound: jinja2.exceptions.TemplateNotFound: index.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: id1.html jinja2.exceptions.TemplateNotFound: ../client/public/index.html jinja2.exceptions.TemplateNotFound: Template.html jinja2.exceptions.TemplateNotFound: www/vet.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFoundjinja2.exceptions.TemplateNotFound raise TemplateNotFound(template)\jinja2.exceptions.TemplateNotFound: jinja2.exceptions.TemplateNotFound: www/index_1.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: homepage.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: jinja2.exceptions.TemplateNotFound: ../results/main.html jinja2.exceptions.TemplateNotFound: www/admin_dash.html jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: _formhelpers.html jinja2.exceptions.templatenotfound welcome.html raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: hello.html jinja2.exceptions.TemplateNotFound: hello.html flask jinja2.exceptions.TemplateNotFound: home.html inja2.exceptions.TemplateNotFound: index.html inja2.exceptions.TemplateNotFound: home.html raise TemplateNotFound(template) TemplateNotFound: index.html exceptions.TemplateNotFound on flask flask jinja2.exceptions.TemplateNotFound: index.html exceptions.TemplateNotFound: ../static/index.html jinja2.exceptions.TemplateNotFound: /home/pi/stream_camera/index.html jinja2.exceptions.TemplateNotFound: student.html flask jinja jinja2.exceptions.TemplateNotFound: jinja2.exceptions.templatenotfound: templates/index.html
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source