簡體   English   中英

異常引發:未找到 {%extends "base.html"%},導致 Heroku 中出現“500 Internal Server Error”

[英]Exception raise: {%extends "base.html"%} not found, causing "500 Internal Server Error" in Heroku

我目前正在嘗試使用 heroku 啟動我的網站。 我觀看了一個 yt 教程並按照所有步驟創建了一個 requirements.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

Procfile(沒有.txt):

web: gunicorn main:app

(與.txt沒有變化)

路由到 index.html:

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

索引.html:

{%extends "base.html"%}

我還嘗試了許多其他方法,例如將所有 _ 取出或使用 '' 而不是 ""。 它們都在本地主機中工作,但不在 heroku 中

此外 base.html 與所有其他模板位於同一文件夾中(文件夾稱為模板)

如果您能提供幫助,非常感謝!

編輯:這是來自 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

所以我終於管理了一些東西,我做了什么,也許在其他一些人有的情況下,我將我的 base.html 移動到名為 base 的第二個文件夾。 然后我寫了同樣的擴展行:

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

最終對我有用的東西。 最后一部分可能與運行時錯誤有關,但已完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM