Forums

Flask Render Template doesn't work despite correct folder structure

Hi all, I have been working on a small flask application recently, it works perfectly on my local PC, however, it is unable to render templates without throwing a jinja2.exceptions.TemplateNotFound error.

Here's the code i'm using to test flask out:

app = Flask("app", static_folder='static', template_folder="templates")

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

Image of my directory structure in bash

I'm fairly certain my directory structure is right, with main.py in the same folder as templates and static. I don't know what could be wrong here, any suggestions?

Where are you seeing the TemplateNotFound errors? I just took a look at your site and it appears to be rendering correctly.

for my own info, why do you need to declare: static_folder='static', template_folder="templates" in your code as these are the default folders for flask anyway?

You're using relative paths for your folders and the working directory is probably not what you think it is. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/