0

I'm new to flask (but not new to Python) and I've been following Corey Schafer's YouTube tutorial on setting things up. I've done everything almost as Corey did in the videos. I'm working with Visual Studio Code on Mac instead of Sublime, which is the only difference.

When I get to the step of using the render_template function to execute basic html files, something is going wrong and I'm getting all kinds of errors. What am I missing?

My flask_blog.py program:

from flask import Flask, render_template
app = Flask(__name__)

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

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

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

home.html:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>Home Page</h1>
</body>
</html>

about.html:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>About Page</h1>
</body>
</html>

And here is what I'm getting when I try navigating to the home page: Screenshot 1/2

Screenshot 2/2

  • 1
    What's unclear about the error? It can't find your template, which means you haven't put it in the right place. But since you haven't said where you put it, we can't help any further. – Daniel Roseman Sep 29 '18 at 16:23
  • Your template was not found. It does not exist or your template loader is not properly configured. – Klaus D. Sep 29 '18 at 16:24

1 Answers1

3

Ensure that you are storing the html files in a subdirectory called templates:

parentfolder
  templates
     home.html
     about.html
  flask_blog.py \\this is the file that contains the route declarations
Ajax1234
  • 69,937
  • 8
  • 61
  • 102
  • I misplaced the templates folder and had it in the wrong location. Silly mistake but thank you. This is my first experience with having to create workspaces with many folders and many files inside the folders. – Dominic Hicks Sep 29 '18 at 17:18