Python jinja2.exceptions.TemplateNotFound:base.html错误

2024-04-25 08:14:47 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我用Flask创建了一个博客,当我在本地运行它时,它运行得很好。但是在日志中的heroku部署中,我得到了一个“raise TemplateNotFound(template)”错误

run.py

from flaskblog import app

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

\uuuu init\uuuuu.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__, template_folder="templates")
app.config['SECRET_KEY'] = '1238944784'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)

from flaskblog import routes

Procfile

web: gunicorn run:app

----flaskblog (Directory)
        Procfile
        requirements.txt
        run.py
--------flaskblog (Directory)
            forms.py
            models.py
            routes.py
            site.db
            __init__.py
------------static (Directory)
                main.css
------------templates (Directory)
                admin.html
                base.html
                edit.html
                home.html
                post.html
                posts.html

在heroku日志中,我得到了“jinja2.exceptions.TemplateNotFound:base.html”错误

这里还有项目的Github存储库:Github Repository


Tags: runnamefrompyimportappflaskdb
1条回答
网友
1楼 · 发布于 2024-04-25 08:14:47

您的每个html文件都有一个简单的输入错误

一些html文件的顶部有此代码,可以从base.html扩展,但结尾有一个空格

你是这样写的

{% extends "base.html "%}

您应该删除结尾处的空格并将其更改为

{% extends "base.html"%}

相关问题 更多 >