0

I tried to render an "html" file using Flask(Jinja2) in Python, but it showed me an error. My controller ".py file":-

from flask import Flask, render_template
app = Flask(__name__)
@app.route("/profile/<name>")
def profile(name):
    return render_template('profile.html', name=name)
if __name__ == "__main__":
    app.run(debug=True)

My template "profile.html" file:

<h1>Welcome To Your Profile, {{ name }}</h1>

When I ran the flask app, it gave me the following exception:-

  jinja2.exceptions.TemplateNotFound: template\profile.html
Anuj Gautam
  • 1,235
  • 1
  • 7
  • 14
Roxas Zohbi
  • 599
  • 4
  • 13
  • 20

2 Answers2

1

The error message says:

jinja2.exceptions.TemplateNotFound: template\profile.html

The templates folder should be named templates (in plural) and saved in the root path of the application. That is how Flask works by default.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
1

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

Avi Mosseri
  • 1,258
  • 1
  • 18
  • 35