引发异常错误:未找到{%extends“base.html”%},导致Heroku中出现“500内部服务器错误”

sirbozc5  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(138)

我目前正在尝试推出我的网站与heroku。我看了一个yt教程,并按照所有的步骤,创建requirement.txt和Procfile。问题发生在我构建我的应用程序时,它成功地部署了它,但在网站本身上,它显示我内部服务器错误。我曾尝试通过localhost运行应用程序,它工作得很完美。我也在谷歌上查了一下,尝试了很多不同网站的建议,都没有成功。
下面是我的代码:requirement.txt:

bcrypt==3.2.2
certifi==2022.6.15
cffi==1.15.1
charset-normalizer==2.1.0
click==8.1.3
colorama==0.4.5
dnspython==2.2.1
email-validator==1.2.1
Flask==2.2.2
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==2.5.1
Flask-WTF==1.0.1
greenlet==1.1.2
gunicorn==20.1.0
idna==3.3
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
pycparser==2.21
requests==2.28.1
SQLAlchemy==1.4.40
tailwind==3.1.5b0
tailwindcss==0.0.1
urllib3==1.26.11
Werkzeug==2.2.2
WTForms==3.0.1

过程文件(不带.txt):

web: gunicorn main:app

(no是否使用.txt更改)
路由到index.html:

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

index.html:

{%extends "base.html"%}

我也尝试了很多其他的方法,比如把all _ out去掉,或者用"“代替“"。它们都可以在localhost中工作,但在heroku中不行
此外,base.html与所有其他模板位于同一文件夹中(文件夹称为模板)
如果你能帮忙的话,非常感谢!
edit:这是来自heroku的日志文件:

2022-08-23T15:43:58.798987+00:00 app[web.1]: 10.1.22.132 - - 
[23/Aug/2022:15:43:58 +0000] "GET / HTTP/1.1" 500 265 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 OPR/89.0.4447.83"

2022-08-23T16:19:26.146143+00:00 heroku[web.1]: Idling
2022-08-23T16:19:26.150788+00:00 heroku[web.1]: State changed from up to down
2022-08-23T16:19:26.884513+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2022-08-23T16:19:27.759152+00:00 app[web.1]: [2022-08-23 16:19:27 +0000] [9] [INFO] Worker exiting (pid: 9)
2022-08-23T16:19:27.759453+00:00 app[web.1]: [2022-08-23 16:19:27 +0000] [4] [INFO] Handling signal: term
2022-08-23T16:19:27.759656+00:00 app[web.1]: [2022-08-23 16:19:27 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-08-23T16:19:27.763711+00:00 app[web.1]: [2022-08-23 16:19:27 +0000] [4] [WARNING] Worker with pid 9 was terminated due to signal 15
2022-08-23T16:19:27.960098+00:00 app[web.1]: [2022-08-23 16:19:27 +0000] [4] [INFO] Shutting down: Master
2022-08-23T16:19:28.110607+00:00 heroku[web.1]: Process exited with status 0
2022-08-23T20:12:39.274284+00:00 heroku[web.1]: Unidling
2022-08-23T20:12:39.286718+00:00 heroku[web.1]: State changed from down to starting
2022-08-23T20:12:41.868461+00:00 heroku[web.1]: Starting process with command `gunicorn main:app`
2022-08-23T20:12:43.054746+00:00 app[web.1]: [2022-08-23 20:12:43 +0000] [4] [INFO] Starting gunicorn 20.1.0
2022-08-23T20:12:43.055108+00:00 app[web.1]: [2022-08-23 20:12:43 +0000] [4] [INFO] Listening at: http://0.0.0.0:3918 (4)
2022-08-23T20:12:43.055151+00:00 app[web.1]: [2022-08-23 20:12:43 +0000] [4] [INFO] Using worker: sync
2022-08-23T20:12:43.058698+00:00 app[web.1]: [2022-08-23 20:12:43 +0000] [9] [INFO] Booting worker with pid: 9
2022-08-23T20:12:43.080341+00:00 app[web.1]: [2022-08-23 20:12:43 +0000] [10] [INFO] Booting worker with pid: 10
2022-08-23T20:12:43.558705+00:00 heroku[web.1]: State changed from starting to up
2022-08-23T20:12:44.824631+00:00 heroku[router]: at=info method=GET path="/" host=theinnerreviewers.herokuapp.com request_id=378490fd-5146-47fb-9f61-141335354858 fwd="31.10.142.137" dyno=web.1 connect=0ms service=425ms status=500 bytes=452 protocol=https
2022-08-23T20:12:44.532717+00:00 app[web.1]: /app/.heroku/python/lib/python3.10/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2022-08-23T20:12:44.532731+00:00 app[web.1]:   warnings.warn(FSADeprecationWarning(
2022-08-23T20:12:44.533796+00:00 app[web.1]: /app/.heroku/python/lib/python3.10/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
2022-08-23T20:12:44.533797+00:00 app[web.1]:   warnings.warn(FSADeprecationWarning(
2022-08-23T20:12:44.826414+00:00 app[web.1]: [2022-08-23 20:12:44,825] ERROR in app: Exception on / [GET]
2022-08-23T20:12:44.826424+00:00 app[web.1]: Traceback (most recent call last):
2022-08-23T20:12:44.826425+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
2022-08-23T20:12:44.826426+00:00 app[web.1]:     response = self.full_dispatch_request()
2022-08-23T20:12:44.826426+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
2022-08-23T20:12:44.826427+00:00 app[web.1]:     rv = self.handle_user_exception(e)
2022-08-23T20:12:44.826427+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
2022-08-23T20:12:44.826427+00:00 app[web.1]:     rv = self.dispatch_request()
2022-08-23T20:12:44.826427+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
2022-08-23T20:12:44.826428+00:00 app[web.1]:     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2022-08-23T20:12:44.826428+00:00 app[web.1]:   File "/app/theinnerreviewers/routes.py", line 40, in index
2022-08-23T20:12:44.826429+00:00 app[web.1]:     return render_template("index.html")
2022-08-23T20:12:44.826429+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/templating.py", line 147, in render_template
2022-08-23T20:12:44.826430+00:00 app[web.1]:     return _render(app, template, context)
2022-08-23T20:12:44.826430+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/templating.py", line 130, in _render
2022-08-23T20:12:44.826430+00:00 app[web.1]:     rv = template.render(context)
2022-08-23T20:12:44.826430+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
2022-08-23T20:12:44.826431+00:00 app[web.1]:     self.environment.handle_exception()
2022-08-23T20:12:44.826431+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
2022-08-23T20:12:44.826431+00:00 app[web.1]:     raise rewrite_traceback_stack(source=source)
2022-08-23T20:12:44.826431+00:00 app[web.1]:   File "/app/theinnerreviewers/templates/index.html", line 1, in top-level template code
2022-08-23T20:12:44.826432+00:00 app[web.1]:     {%extends "base.html"%}
2022-08-23T20:12:44.826433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/templating.py", line 62, in get_source
2022-08-23T20:12:44.826433+00:00 app[web.1]:     return self._get_source_fast(environment, template)
2022-08-23T20:12:44.826433+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.10/site-packages/flask/templating.py", line 98, in _get_source_fast
2022-08-23T20:12:44.826433+00:00 app[web.1]:     raise TemplateNotFound(template)
2022-08-23T20:12:44.826434+00:00 app[web.1]: jinja2.exceptions.TemplateNotFound: base.html
2022-08-23T20:12:44.827771+00:00 app[web.1]: 10.1.45.191 - - [23/Aug/2022:20:12:44 +0000] "GET / HTTP/1.1" 500 265 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10
dced5bon

dced5bon1#

所以我最终做了一些事情,我做了什么,也许在其他一些情况下,其他人也做了什么,我把我的base.html移到了第二个文件夹base中,然后我写了同样的extends行,如下所示:

{% extends "base/base.html"%}

最后一部分可能与运行时错误有关,但这已经完成。

相关问题