Snouter
Snouter

Reputation: 1

Internal 500 Error - home.html cannot be found

I'm trying to deploy a website with Heroku. However, I get a 500 internal error. Upon inspection, it seems that the main page "home.html" cannot be located. However, when I check the website locally, it works fine. What could be wrong here?

Here's a chunk of the error log detailing my issue:

raise TemplateNotFound(template)
2021-02-27T15:50:34.531564+00:00 app[web.1]: jinja2.exceptions.TemplateNotFound: home.html 

[2021-02-27 15:50:34,526] ERROR in app: Exception on / [GET]
2021-02-27T15:50:34.531544+00:00 app[web.1]: Traceback (most recent call last):
2021-02-27T15:50:34.531546+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/flask/app.py", line 2

Here's the python code used to deploy the website:


app=Flask(__name__)

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

@app.route('/full library/')
def full_lib():
    return render_template("full library.html")

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

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

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

It's a simple app so far and works locally no issue. However, upon deployment, I get an error. I was getting an application issue before but I found it was a simple spelling mistake. I did also bring the files over from a different folder but they have been saved and checked over since.

Upvotes: 0

Views: 37

Answers (1)

Rivers
Rivers

Reputation: 1923

Did you create a folder named templates ?

You have to place your template files (for example your "home.html") in this folder.

From the documentation (https://flask.palletsprojects.com/en/1.1.x/quickstart/):

Flask will look for templates in the templates folder. So if your application is a module, this folder is next to that module, if it’s a package it’s actually inside your package:

Case 1: a module:

/application.py
/templates
    /hello.html

Case 2: a package:

/application
    /__init__.py
    /templates
        /hello.html

Upvotes: 1

Related Questions