Flask raises TemplateNotFound error even though template file exists

前端 未结 11 1552
别跟我提以往
别跟我提以往 2020-11-21 23:02

I am trying to render the file home.html. The file exists in my project, but I keep getting jinja2.exceptions.TemplateNotFound: home.html when I t

11条回答
  •  孤城傲影
    2020-11-21 23:25

    (Please note that the above accepted Answer provided for file/project structure is absolutely correct.)

    Also..

    In addition to properly setting up the project file structure, we have to tell flask to look in the appropriate level of the directory hierarchy.

    for example..

        app = Flask(__name__, template_folder='../templates')
    
        app = Flask(__name__, template_folder='../templates', static_folder='../static')
    

    Starting with ../ moves one directory backwards and starts there.

    Starting with ../../ moves two directories backwards and starts there (and so on...).

    Hope this helps

提交回复
热议问题