添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am facing an issue while setting up a simple Flask application to create a web page. When I run the application and access it in the browser, I receive an error message

jinja2.exceptions.TemplateNotFound: index.html

The directory structure of my project is as follows:

├── app.py
├── templates
│   └── index.html
└── ...

I have checked and confirmed that the "index.html" file is indeed placed within the "templates" directory and the file name is spelled correctly.

Here is the source code of the "app.py" file:

from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
    return render_template('index.html')
if __name__ == '__main__':
    app.run()

And here is the content of the "index.html" file:

<!DOCTYPE html>
      <title>Intelligent Processing System</title>
  </head>
      <h1>Intelligent Processing System</h1>
 Other content of the web page -->
  </body>
</html>

I am using Flask version 2.3.2.

I tried running a Flask application with the expectation that the "index.html" file would be successfully rendered when accessing the application in the browser. However, I encountered the error "jinja2.exceptions.TemplateNotFound: index.html".

I have double-checked the directory structure and file names, and everything seems to be in order. The "index.html" file is located in the "templates" directory, and the file name is spelled correctly.

I expected that when I accessed the application in the browser, the web page would display the content defined in the "index.html" file. However, the error mentioned above occurred instead.

I copied and pasted your code and it works as expected on my machine. Maybe triple check the spelling and make sure there are no extra characters or whitespace in the names of index.html and the templates directory. – Rob May 19 at 5:11

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.