Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm can't find Flask template that exists

PyCharm's code editor shows the popup message Template file 'index.html' not found when passing "index.html" to render_template. The template templates/index.html exists. Accessing http://localhost:5000/ renders the template. How do I tell PyCharm that the template exists?

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

enter image description here

like image 909
nalzok Avatar asked Jul 10 '17 16:07

nalzok


People also ask

How do I fix Flask template not found?

Make sure that you have a file called index. html in the directory where you have configured Flask to look for templates (it's usually a directory called 'templates' in your web app directory).

Where are Flask templates found?

Flask looks for templates in the templates directory, which is called templates , so the name is important. Make sure you're inside the flask_app directory and run the following command to create the templates directory: mkdir templates.

How do I fix jinja2 exceptions Templatenotfound?

To resolve the issue, simply create a folder name it “Templates”. Then move “index. html” into this newly created folder.


1 Answers

Right click on your templates directory, go to "Mark Directory as", and select "Template Directory".

like image 58
davidism Avatar answered Sep 19 '22 23:09

davidism