-1

I am trying to render the template of index.html using Flask. I get an error that the file is not found. The error is jinja2.exceptions.TemplateNotFound: template/index.html. The file exists in the templates folder and it has the name index.html

`from flask import Flask, render_template



app = Flask(__name__, template_folder="template")

@app.route("/")
def home():
    return render_template("template/index.html")



if __name__ == "__main__":
    app.run(debug=True)`

I have already tried creating a directory called templates and putting the html file there - as suggested to some users here
I also tried changing the name of the files and the directory (template and templates)
I have tried importing jinja2
Nemiya
  • 11
  • 1

1 Answers1

0

You need to remove the template/ prefix from render_template argument. You already specified, that templates will be located in template folder, so you need to supply only the filename of the template to the render_template function.

This will work if there is a template named index.html in template folder.

from flask import Flask, render_template



app = Flask(__name__, template_folder="template")

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



if __name__ == "__main__":
    app.run(debug=True)
matusf
  • 469
  • 1
  • 8
  • 20