简体   繁体   English

异常引发:未找到 {%extends "base.html"%},导致 Heroku 中出现“500 Internal Server Error”

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

I currently trying to launch my website with heroku.我目前正在尝试使用 heroku 启动我的网站。 I watched a yt tutorial and followed all the steps, creating a requirement.txt and Procfile.我观看了一个 yt 教程并按照所有步骤创建了一个 requirements.txt 和 Procfile。 The problem occurs when I build my application it successfully deploys it but on the website itself it shows me Internal Server Error.当我构建我的应用程序时出现问题,它成功部署了它,但在网站本身上它显示了内部服务器错误。 I have tried to run the app through localhost and it works perfectly.我试图通过 localhost 运行该应用程序,它运行良好。 I also looked up on google and tried many suggestions from different sites without success.我还查了谷歌,尝试了许多来自不同网站的建议,但都没有成功。

Here is my code: requirement.txt:这是我的代码: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 (without.txt): Procfile(没有.txt):

web: gunicorn main:app

(no change with.txt or not) (与.txt没有变化)

route to index.html:路由到 index.html:

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

index.html:索引.html:

{%extends "base.html"%}

I also tried many other ways, like taking all _ out or have '' instead of "".我还尝试了许多其他方法,例如将所有 _ 取出或使用 '' 而不是 ""。 They all work in localhost but not in heroku它们都在本地主机中工作,但不在 heroku 中

Also base.html is in the same folder as all other templates (folder is called templates)此外 base.html 与所有其他模板位于同一文件夹中(文件夹称为模板)

Thank you so much if you can help!如果您能提供帮助,非常感谢!

edit: This is the log file from heroku:编辑:这是来自 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

So I finally managed something, what I did and maybe in some other cases that other people had, that I moved my base.html to a second folder called base.所以我终于管理了一些东西,我做了什么,也许在其他一些人有的情况下,我将我的 base.html 移动到名为 base 的第二个文件夹。 I then wrote the same extends line like that:然后我写了同样的扩展行:

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

what finally worked for me.最终对我有用的东西。 The last part stays probably with the runtime error but this is done.最后一部分可能与运行时错误有关,但已完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM