我正在尝试将django Web应用程序第一次部署到heroku,但是我仍然收到500个服务器错误。
这是我查看日志时看到的:
2020-07-30T05:03:27.965070+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 423, in stored_name
2020-07-30T05:03:27.965070+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2020-07-30T05:03:27.965070+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'favicon.png'
2020-07-30T05:03:27.965366+00:00 heroku[router]: at=info method=GET path="/" host=programatic-learning.herokuapp.com request_id=1332a937-88d1-48f0-8aac-0847852e467d fwd="67.70.149.199" dyno=web.1 connect=1ms service=72ms status=500 bytes=380 protocol=https
2020-07-30T05:03:27.965534+00:00 app[web.1]: 10.63.123.248 - - [30/Jul/2020:05:03:27 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
2020-07-30T05:33:17.000000+00:00 app[api]: Build started by user stephenlang91@gmail.com
2020-07-30T05:34:28.791656+00:00 app[api]: Deploy 599627a3 by user stephenlang91@gmail.com
2020-07-30T05:34:28.791656+00:00 app[api]: Release v8 created by user stephenlang91@gmail.com
2020-07-30T05:34:28.961452+00:00 heroku[web.1]: Restarting
2020-07-30T05:34:28.976045+00:00 heroku[web.1]: State changed from up to starting
2020-07-30T05:34:30.150144+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-30T05:34:30.184774+00:00 app[web.1]: [2020-07-30 05:34:30 +0000] [9] [INFO] Worker exiting (pid: 9)
2020-07-30T05:34:30.184787+00:00 app[web.1]: [2020-07-30 05:34:30 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-07-30T05:34:30.185022+00:00 app[web.1]: [2020-07-30 05:34:30 +0000] [4] [INFO] Handling signal: term
2020-07-30T05:34:30.385825+00:00 app[web.1]: [2020-07-30 05:34:30 +0000] [4] [INFO] Shutting down: Master
2020-07-30T05:34:30.461780+00:00 heroku[web.1]: Process exited with status 0
2020-07-30T05:34:35.278873+00:00 heroku[web.1]: Starting process with command `gunicorn blog.wsgi --log-file -`
2020-07-30T05:34:37.599742+00:00 app[web.1]: [2020-07-30 05:34:37 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-30T05:34:37.600287+00:00 app[web.1]: [2020-07-30 05:34:37 +0000] [4] [INFO] Listening at: http://0.0.0.0:48523 (4)
2020-07-30T05:34:37.600382+00:00 app[web.1]: [2020-07-30 05:34:37 +0000] [4] [INFO] Using worker: sync
2020-07-30T05:34:37.604437+00:00 app[web.1]: [2020-07-30 05:34:37 +0000] [9] [INFO] Booting worker with pid: 9
2020-07-30T05:34:37.639379+00:00 app[web.1]: [2020-07-30 05:34:37 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-30T05:34:38.101374+00:00 heroku[web.1]: State changed from starting to up
2020-07-30T05:34:41.000000+00:00 app[api]: Build succeeded
2020-07-30T05:38:24.000000+00:00 app[api]: Build started by user stephenlang91@gmail.com
2020-07-30T05:39:02.657678+00:00 app[api]: Deploy 3d9368e9 by user stephenlang91@gmail.com
2020-07-30T05:39:02.657678+00:00 app[api]: Release v9 created by user stephenlang91@gmail.com
2020-07-30T05:39:03.352630+00:00 heroku[web.1]: Restarting
2020-07-30T05:39:03.402931+00:00 heroku[web.1]: State changed from up to starting
2020-07-30T05:39:04.283201+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-07-30T05:39:04.311638+00:00 app[web.1]: [2020-07-30 05:39:04 +0000] [9] [INFO] Worker exiting (pid: 9)
2020-07-30T05:39:04.311661+00:00 app[web.1]: [2020-07-30 05:39:04 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-07-30T05:39:04.312282+00:00 app[web.1]: [2020-07-30 05:39:04 +0000] [4] [INFO] Handling signal: term
2020-07-30T05:39:04.412999+00:00 app[web.1]: [2020-07-30 05:39:04 +0000] [4] [INFO] Shutting down: Master
2020-07-30T05:39:04.491807+00:00 heroku[web.1]: Process exited with status 0
2020-07-30T05:39:09.141751+00:00 heroku[web.1]: Starting process with command `gunicorn blog.wsgi --log-file -`
2020-07-30T05:39:11.144686+00:00 app[web.1]: [2020-07-30 05:39:11 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-07-30T05:39:11.145279+00:00 app[web.1]: [2020-07-30 05:39:11 +0000] [4] [INFO] Listening at: http://0.0.0.0:13003 (4)
2020-07-30T05:39:11.145386+00:00 app[web.1]: [2020-07-30 05:39:11 +0000] [4] [INFO] Using worker: sync
2020-07-30T05:39:11.148931+00:00 app[web.1]: [2020-07-30 05:39:11 +0000] [9] [INFO] Booting worker with pid: 9
2020-07-30T05:39:11.241279+00:00 app[web.1]: [2020-07-30 05:39:11 +0000] [10] [INFO] Booting worker with pid: 10
2020-07-30T05:39:11.342896+00:00 heroku[web.1]: State changed from starting to up
2020-07-30T05:39:13.000000+00:00 app[api]: Build succeeded
2020-07-30T05:39:21.664213+00:00 app[web.1]: [2020-07-30 05:39:21,539] log: ERROR - Internal Server Error: /
2020-07-30T05:39:21.664235+00:00 app[web.1]: Traceback (most recent call last):
2020-07-30T05:39:21.664235+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
2020-07-30T05:39:21.664239+00:00 app[web.1]: response = get_response(request)
2020-07-30T05:39:21.664239+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
2020-07-30T05:39:21.664240+00:00 app[web.1]: response = self.process_exception_by_middleware(e, request)
2020-07-30T05:39:21.664240+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
2020-07-30T05:39:21.664240+00:00 app[web.1]: response = wrapped_callback(request, *callback_args, **callback_kwargs)
2020-07-30T05:39:21.664241+00:00 app[web.1]: File "/app/posts/views.py", line 88, in index
2020-07-30T05:39:21.664241+00:00 app[web.1]: return render(request, "index.html", context)
2020-07-30T05:39:21.664242+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/shortcuts.py", line 19, in render
2020-07-30T05:39:21.664242+00:00 app[web.1]: content = loader.render_to_string(template_name, context, request, using=using)
2020-07-30T05:39:21.664243+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader.py", line 62, in render_to_string
2020-07-30T05:39:21.664243+00:00 app[web.1]: return template.render(context, request)
2020-07-30T05:39:21.664243+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
2020-07-30T05:39:21.664244+00:00 app[web.1]: return self.template.render(context)
2020-07-30T05:39:21.664244+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 171, in render
2020-07-30T05:39:21.664244+00:00 app[web.1]: return self._render(context)
2020-07-30T05:39:21.664245+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
2020-07-30T05:39:21.664245+00:00 app[web.1]: return self.nodelist.render(context)
2020-07-30T05:39:21.664245+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-07-30T05:39:21.664245+00:00 app[web.1]: bit = node.render_annotated(context)
2020-07-30T05:39:21.664246+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-07-30T05:39:21.664246+00:00 app[web.1]: return self.render(context)
2020-07-30T05:39:21.664247+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
2020-07-30T05:39:21.664247+00:00 app[web.1]: return compiled_parent._render(context)
2020-07-30T05:39:21.664247+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
2020-07-30T05:39:21.664248+00:00 app[web.1]: return self.nodelist.render(context)
2020-07-30T05:39:21.664248+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-07-30T05:39:21.664249+00:00 app[web.1]: bit = node.render_annotated(context)
2020-07-30T05:39:21.664249+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-07-30T05:39:21.664249+00:00 app[web.1]: return self.render(context)
2020-07-30T05:39:21.664250+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/loader_tags.py", line 188, in render
2020-07-30T05:39:21.664250+00:00 app[web.1]: return template.render(context)
2020-07-30T05:39:21.664250+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 173, in render
2020-07-30T05:39:21.664251+00:00 app[web.1]: return self._render(context)
2020-07-30T05:39:21.664251+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 163, in _render
2020-07-30T05:39:21.664251+00:00 app[web.1]: return self.nodelist.render(context)
2020-07-30T05:39:21.664251+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 936, in render
2020-07-30T05:39:21.664252+00:00 app[web.1]: bit = node.render_annotated(context)
2020-07-30T05:39:21.664252+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
2020-07-30T05:39:21.664252+00:00 app[web.1]: return self.render(context)
2020-07-30T05:39:21.664253+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/templatetags/static.py", line 106, in render
2020-07-30T05:39:21.664253+00:00 app[web.1]: url = self.url(context)
2020-07-30T05:39:21.664253+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/templatetags/static.py", line 103, in url
2020-07-30T05:39:21.664254+00:00 app[web.1]: return self.handle_simple(path)
2020-07-30T05:39:21.664254+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/templatetags/static.py", line 118, in handle_simple
2020-07-30T05:39:21.664254+00:00 app[web.1]: return staticfiles_storage.url(path)
2020-07-30T05:39:21.664255+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 153, in url
2020-07-30T05:39:21.664255+00:00 app[web.1]: return self._url(self.stored_name, name, force)
2020-07-30T05:39:21.664255+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url
2020-07-30T05:39:21.664256+00:00 app[web.1]: hashed_name = hashed_name_func(*args)
2020-07-30T05:39:21.664256+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 423, in stored_name
2020-07-30T05:39:21.664256+00:00 app[web.1]: raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2020-07-30T05:39:21.664257+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'favicon.png'
2020-07-30T05:39:21.665015+00:00 app[web.1]: 10.35.189.198 - - [30/Jul/2020:05:39:21 +0000] "GET / HTTP/1.1" 500 145 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36"
2020-07-30T05:39:21.667548+00:00 heroku[router]: at=info method=GET path="/" host=programatic-learning.herokuapp.com request_id=dbb0611a-1960-4217-81e0-829e942d4cb8 fwd="67.70.149.199" dyno=web.1 connect=1ms service=235ms status=500 bytes=380 protocol=https
在我看来,问题是这个ValueError: Missing staticfiles manifest entry for 'favicon.png'
但是我在唯一引用favicon.png的模板中将其注释掉。我想知道settings.py文件中是否有问题。我在这方面很新,我正在使用whitenoise加载我的静态文件。也许我搞砸了一些路径:
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static_in_env')]
VENV_PATH = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(VENV_PATH, 'static_root')
MEDIA_ROOT = os.path.join(VENV_PATH, 'media_root')
# Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
如果您想签出我的代码,请点击这里:https://github.com/Kaizen91/ProgramaticLearning
关于我在哪里出问题的任何想法吗?
答案 0 :(得分:2)
我明白为什么这会造成一些混乱,但是就Django而言,您实际上并没有将其注释掉:
<!-- <link rel="shortcut icon" href="{% static 'favicon.png' %}"> -->
您已在其中添加了HTML注释,这意味着浏览器将不再显示它,但是Django仍将在HTML中生成该行,因此它仍必须处理static
指令。
如果您使用如下所示的Django template comments,它将起作用:
{# <link rel="shortcut icon" href="{% static 'favicon.png' %}"> #}
在部署第一个站点时,如果暂时在设置中对此行进行注释,则可能会更容易:
# Add configuration for static files storage using whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
此设置有助于提高网站的性能,但是这意味着对丢失的静态文件的任何引用都将引发错误。首先,如果没有此功能,则可以更轻松地启动并运行您的网站,然后在确定其他所有功能都可以正常工作时,随后再启用它。