djangoherokustaticwhitenoise

ValueError: Missing staticfiles manifest entry for 'favicon.png'


I'm trying to deploy my django web app to heroku for the first time, but I keep getting a 500 server error.

This is what I see when I check the logs:

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

It seems to me the issue is this ValueError: Missing staticfiles manifest entry for 'favicon.png' however I've commented it out in the only template that references favicon.png. I'm wondering if there is something wrong in the settings.py file. I'm pretty new at this and I'm using whitenoise to load my static files. Maybe I've screwed up some of the paths:

# 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',
]

Here's a link to my code if you'd like to check it out: https://github.com/Kaizen91/ProgramaticLearning

Any ideas on where I'm going wrong here?


Solution

  • I can see why this would be a bit confusing, but you haven't actually commented it out as far as Django is concerned:

        <!-- <link rel="shortcut icon" href="{% static 'favicon.png' %}"> -->
    

    You've added HTML comments around it which means that the browser will no longer display it, but Django will still generate that line in the HTML and so it still has to process the static directive.

    It would work if you used Django template comments which look like this:

        {# <link rel="shortcut icon" href="{% static 'favicon.png' %}"> #}
    

    While you're deploying your first site you might find it easier if you temporarily comment out this line in your settings:

    #  Add configuration for static files storage using whitenoise
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    

    This setting helps with the performance of your site, but it will mean that any references to missing static files will throw an error. It might be easier to get your site up and running without this at first, and then enable it later when you're sure everything else is working.