11

I know that there are a lot of questions about that, but to be honest most of them stays unanswered or the solutions do not work.

I have "simple" problem. When I set Debug to False and push it to heroku I get "Server Error (500)". I read those topics:

Heroku server error (500) when Debug = False , whitenoise could not find style.css

Whenever debug=False in django, Heroku gives Server Error (500) and when debug=True no error

https://www.reddit.com/r/djangolearning/comments/acj65x/why_am_i_getting_a_500_server_error_when/

https://teamtreehouse.com/community/heroku-bad-request-500

And I tried their solutions but it still don't work. Only solution that I didn't test and is supposed to help is to get rid of whitenoise. This one is kinda "no go" for me.

What Can I do about this error?

Thanks and Cheers!

EDIT:

Here is my log. I tried to comment out white noise but It didn't help.

I was looking in my code but I don't have any reference to "favicon.ico". Also, I tried to run collectstatic because I found some topics related to that but it didn't work for me.

First it asked me:

You have requested to collect static files at the destination
location as specified in your settings:

    /app/staticfiles

And then I got error:

FileNotFoundError: [Errno 2] No such file or directory: '/app/static'

Which is weird, because first it confirmed with me that I overrited this folder from static to staticfiles. In my main directory I have folder "staticfiles". In my app folder I have folder "static". And with Debug off everything is working.

    2020-05-19T05:15:40.192943+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=robotbuilder.herokuapp.com request_id=eeaf4fd1-b73b-4e84-aacd-7e701d3e8932 fwd="83.26.255.146" dyno=web.1 connect=1ms service=3ms status=404 bytes=388 protocol=http

2020-05-19T05:15:39.991705+00:00 app[web.1]: [2020-05-19 05:15:39 +0000] [11] [ERROR] Error handling request /

2020-05-19T05:15:39.991725+00:00 app[web.1]: Traceback (most recent call last):

2020-05-19T05:15:39.991726+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 134, in handle

2020-05-19T05:15:39.991734+00:00 app[web.1]:     self.handle_request(listener, req, client, addr)

2020-05-19T05:15:39.991734+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 175, in handle_request

2020-05-19T05:15:39.991735+00:00 app[web.1]:     respiter = self.wsgi(environ, resp.start_response)

2020-05-19T05:15:39.991735+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 133, in __call__

2020-05-19T05:15:39.991735+00:00 app[web.1]:     response = self.get_response(request)

2020-05-19T05:15:39.991736+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 75, in get_response

2020-05-19T05:15:39.991736+00:00 app[web.1]:     response = self._middleware_chain(request)

2020-05-19T05:15:39.991736+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991737+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991739+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991740+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991741+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991741+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991741+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/whitenoise/middleware.py", line 58, in __call__

2020-05-19T05:15:39.991742+00:00 app[web.1]:     response = self.get_response(request)

2020-05-19T05:15:39.991746+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991747+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991747+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991747+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991747+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991748+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991748+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991748+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991748+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991749+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991749+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991749+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991750+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991750+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991750+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991750+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991751+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991751+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991751+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991752+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991752+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991752+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991752+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991753+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991753+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991753+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991753+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991754+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991754+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991755+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991763+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991763+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991763+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991764+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991764+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991764+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991764+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991765+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991765+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991765+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991766+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991766+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991766+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991766+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991767+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991767+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991767+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991767+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991768+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991768+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991768+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991768+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991769+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991769+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/deprecation.py", line 94, in __call__

2020-05-19T05:15:39.991769+00:00 app[web.1]:     response = response or self.get_response(request)

2020-05-19T05:15:39.991769+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991770+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991770+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991770+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991771+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991771+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991771+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/whitenoise/middleware.py", line 58, in __call__

2020-05-19T05:15:39.991771+00:00 app[web.1]:     response = self.get_response(request)

2020-05-19T05:15:39.991772+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 36, in inner

2020-05-19T05:15:39.991772+00:00 app[web.1]:     response = response_for_exception(request, exc)

2020-05-19T05:15:39.991772+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 90, in response_for_exception

2020-05-19T05:15:39.991772+00:00 app[web.1]:     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())

2020-05-19T05:15:39.991780+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner

2020-05-19T05:15:39.991781+00:00 app[web.1]:     response = get_response(request)

2020-05-19T05:15:39.991781+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response

2020-05-19T05:15:39.991782+00:00 app[web.1]:     response = self.process_exception_by_middleware(e, request)

2020-05-19T05:15:39.991782+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response

2020-05-19T05:15:39.991782+00:00 app[web.1]:     response = wrapped_callback(request, *callback_args, **callback_kwargs)

2020-05-19T05:15:39.991783+00:00 app[web.1]:   File "/app/builder/views.py", line 8, in home

2020-05-19T05:15:39.991783+00:00 app[web.1]:     return render(request, "builder/home.html")

2020-05-19T05:15:39.991783+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/shortcuts.py", line 19, in render

2020-05-19T05:15:39.991784+00:00 app[web.1]:     content = loader.render_to_string(template_name, context, request, using=using)

2020-05-19T05:15:39.991790+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py", line 62, in render_to_string

2020-05-19T05:15:39.991790+00:00 app[web.1]:     return template.render(context, request)

2020-05-19T05:15:39.991791+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py", line 61, in render

2020-05-19T05:15:39.991791+00:00 app[web.1]:     return self.template.render(context)

2020-05-19T05:15:39.991791+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 171, in render

2020-05-19T05:15:39.991792+00:00 app[web.1]:     return self._render(context)

2020-05-19T05:15:39.991792+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 163, in _render

2020-05-19T05:15:39.991792+00:00 app[web.1]:     return self.nodelist.render(context)

2020-05-19T05:15:39.991792+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 936, in render

2020-05-19T05:15:39.991793+00:00 app[web.1]:     bit = node.render_annotated(context)

2020-05-19T05:15:39.991793+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated

2020-05-19T05:15:39.991798+00:00 app[web.1]:     return self.render(context)

2020-05-19T05:15:39.991798+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py", line 150, in render

2020-05-19T05:15:39.991798+00:00 app[web.1]:     return compiled_parent._render(context)

2020-05-19T05:15:39.991799+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 163, in _render

2020-05-19T05:15:39.991799+00:00 app[web.1]:     return self.nodelist.render(context)

2020-05-19T05:15:39.991799+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 936, in render

2020-05-19T05:15:39.991799+00:00 app[web.1]:     bit = node.render_annotated(context)

2020-05-19T05:15:39.991800+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py", line 903, in render_annotated

2020-05-19T05:15:39.991800+00:00 app[web.1]:     return self.render(context)

2020-05-19T05:15:39.991800+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 106, in render

2020-05-19T05:15:39.991800+00:00 app[web.1]:     url = self.url(context)

2020-05-19T05:15:39.991804+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 103, in url

2020-05-19T05:15:39.991804+00:00 app[web.1]:     return self.handle_simple(path)

2020-05-19T05:15:39.991804+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py", line 118, in handle_simple

2020-05-19T05:15:39.991805+00:00 app[web.1]:     return staticfiles_storage.url(path)

2020-05-19T05:15:39.991805+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 153, in url

2020-05-19T05:15:39.991805+00:00 app[web.1]:     return self._url(self.stored_name, name, force)

2020-05-19T05:15:39.991806+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 132, in _url

2020-05-19T05:15:39.991806+00:00 app[web.1]:     hashed_name = hashed_name_func(*args)

2020-05-19T05:15:39.991806+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 423, in stored_name

2020-05-19T05:15:39.991806+00:00 app[web.1]:     raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)

2020-05-19T05:15:39.991807+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'builder/logo.png'

2020-05-19T05:15:39.992027+00:00 app[web.1]: 10.95.191.28 - - [19/May/2020:05:15:39 +0000] "GET / HTTP/1.1" 500 0 "-" "-"

2020-05-19T05:15:40.192825+00:00 app[web.1]: 10.95.191.28 - - [19/May/2020:05:15:40 +0000] "GET /favicon.ico HTTP/1.1" 404 179 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"

2020-05-19T05:15:39.996509+00:00 heroku[router]: at=info method=GET path="/" host=robotbuilder.herokuapp.com request_id=de877e93-558a-40ab-bf11-b6de261cb707 fwd="83.26.255.146" dyno=web.1 connect=1ms service=57ms status=500 bytes=244 protocol=http

EDIT2:

    import os
import django_heroku
from decouple import config
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'builder',
]

MIDDLEWARE = [
    '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',
    # Simplified static file serving.
    # https://warehouse.python.org/project/whitenoise/
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'robot_builder.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'robot_builder.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
    }
}
# If you want to work with your remote database on your local machine, you need to paste link from heroku lower:
# DATABASES['default'] = dj_database_url.config(default='postgres://qkwlkrkahynyik:21a1420ab5820795f3a0c736ebb607419fc7a111f093924dcfc4567dfd906b9f@ec2-54-147-209-121.compute-1.amazonaws.com:5432/d2v01dp40p4er2')

db_from_env = dj_database_url.config(conn_max_age=600)
DATABASES['default'].update(db_from_env)

# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_TMP = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


 # Debugging in heroku live
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
                       'pathname=%(pathname)s lineno=%(lineno)s ' +
                       'funcname=%(funcName)s %(message)s'),
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        }
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'testlogger': {
            'handlers': ['console'],
            'level': 'INFO',
        }
    }
}

DEBUG_PROPAGATE_EXCEPTIONS = True
COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)


# Activate Django-Heroku.
django_heroku.settings(locals())

My folder structure:

robot_builder
    > builder
        >> migrations
        >> static
            >>> css
            >>> builder
                >>>> my images, including logo.png used as favicon
        >> templates
        >> models.py etc.
    > media
    > robot_builder
        >> settings.py etc.
    > staticfiles
Peksio
  • 525
  • 6
  • 25
  • 1
    try once without whitenoise just to see if it is causing problems. – Hisham___Pak May 17 '20 at 15:29
  • I tried to comment out whitenoise but it didn't help, I added my logs in edited post. – Peksio May 19 '20 at 05:30
  • 1
    Please edit your post so it includes static settings. – Hisham___Pak May 19 '20 at 13:29
  • I addded my whole settings.py code – Peksio May 19 '20 at 18:15
  • 1
    Please also show your directory structure and what is `STATIC_TMP = os.path.join(BASE_DIR, 'static')`? – Hisham___Pak May 19 '20 at 19:46
  • Of course, I added my folder structure in my first post. To be honest I was following heroku deploy tutorial including creation of this folder. But in my main directory I have folder "staticfiles" not "static". "static" is inside of my app folder. – Peksio May 19 '20 at 20:07
  • 1
    If your `staticfiles/` folder contain nothing you can delete it and take your `static/` folder to the same level as `staticfiles/` in root dir. Then test it it will work. – Hisham___Pak May 19 '20 at 20:29
  • I moved my "static" folder to the same level but it still didn't work. This time I get error "ValueError: Missing staticfiles manifest entry for 'builder/logo.png'" I googled it and it told me to run command "heroku run python manage.py collectstatic". Heroku gave me message "154 static files copied to '/app/staticfiles'." Which is weird because in my app folder there is no folder "staticfiles" (?) and it gives me Internal Server Error. I also tried to set my static exactly like here: https://github.com/flatplanet/My-Address-Book/blob/master/mysite/settings.py but still the same error :/ – Peksio May 20 '20 at 05:09

5 Answers5

8

I think I got it. The solution is working. But I think that it's also very weird. I would appreciate if someone could comment why is it like that.

You can leave whitenoise, you can make a little bit tidying up with static files dirs. Make it look like that:

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')


STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

But it isn't necessary I think. (It is also best to keep your "static" folder in your main project folder).

But The big fix is (working on django 3):

You need to run

python manage.py collectstatic

Locally ! And then submit it to heroku. And then, everything is working with Debug set to False. I tried to keep collectstatic just with .keep file. I tried to commit only .json hoping that it will be repopulated with new collectstatic files. But no. It is working only if I run collectstatic locally and then commit EVERYTHING to heroku.

If someone have more understanding of this issue and could explain it to me I would be really grateful.

In the mean time I hope that someone else will also benefit from this solution.

I found answer on this question - ValueError: Missing staticfiles manifest entry for 'favicon.ico' . Thank you very much emazzotta, also I didn't have to get rid of whitenoise and It is working in django3.

Peksio
  • 525
  • 6
  • 25
  • 2
    You saved my life. I spent two weeks fighting with django and heroku. Your post solved everything smoothly!!! Thank you. I use a folder called settings with two configuration files. So, the unique difference is the BASE_DIR everything else was equal. – Arvieira Aug 10 '21 at 16:06
6

Debug your django app by logs by typing this, heroku logs --tail -a your_herokuapp_name or https://dashboard.heroku.com/apps/your_herokuapp_name/logs.

Before that add this in your settings.py:

 # Debugging in heroku live
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' +
                       'pathname=%(pathname)s lineno=%(lineno)s ' +
                       'funcname=%(funcName)s %(message)s'),
            'datefmt': '%Y-%m-%d %H:%M:%S'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        }
    },
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'logging.NullHandler',
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        }
    },
    'loggers': {
        'testlogger': {
            'handlers': ['console'],
            'level': 'INFO',
        }
    }
}

DEBUG_PROPAGATE_EXCEPTIONS = True
COMPRESS_ENABLED = os.environ.get('COMPRESS_ENABLED', False)

This will show you error with debug=False in heroku logs.

STACKOVERFLOW QUESTION [SOURCE]

Hisham___Pak
  • 1,472
  • 1
  • 11
  • 23
  • 1
    Thank you, I edited my first post with additional informations and logs. Can you please take a look at that? – Peksio May 19 '20 at 05:31
  • 1
    Hi. I also tried a bunch of solutions from this thread - https://stackoverflow.com/questions/44160666/valueerror-missing-staticfiles-manifest-entry-for-favicon-ico Yet no luck, I am running out of random ideas to try :/ – Peksio May 21 '20 at 04:59
0

ValueError: Missing staticfiles manifest entry for 'builder/logo.png'

It seems that in builder/staticfiles(/builder), logo.png is referenced but doesn't exist. It might be that it's trying to get to static rather than staticfiles, in which case that seems to be an internal error that would be patched out in a later version of Django. Seeing as you're using Django 2, you should probably upgrade to Django 3 if adding logo.png doesn't work.

TL;DR: Add logo.png to builder/staticfiles(/builder) or upgrade Django.

Electroboss
  • 99
  • 1
  • 10
0

I had the same problem and in my case, I was linking to a css file that didn't exist.

For example:

{% block head %}
    <link rel="stylesheet" href="{% static 'css/my-styles.css' %}">
{% endblock %}

Whereas there was actually no my-styles.css file.

I have removed the link and after that the app started to work with both settings of DEBUG (True and False).

0

okay so it's probably because you left out some important imports. when DEBUG = False django will not handle your static files so we need our remote server to handle that. This is the process to fix that:

  1. go to your project directory (where manage.py exists) in your command line.

  2. pip install whitenoise then make sure it is added to your requirements.txt by doing pip freeze > requirements.txt if this is already there's no problem.

  3. go to your settings.py folder and locate MIDDLEWARE. add 'whitenoise.middleware.WhiteNoiseMiddleware', to it.

  4. in the same settings.py add STATIC_ROOT = os.path.join(BASE_DIR, 'static') for my case it was just above django_heroku.settings(locals()) note: the 'static' there is just the name of the directory where your static files are stored.

  5. now go to your wsgi.py file in the same directory as settings.py type the following at the top from whitenoise import WhiteNoise also at the bottom you will use the import so add application = WhiteNoise(application)

  6. now change DEBUG = False and go back to the command prompt in the project directory

  7. type python manage.py collectstatic after this a new folder will appear in the root directory of your project . Just leave it there

  8. do git add . and git commit -m "description"

  9. push to your remote server. for example git push heroku master for heroku

I hope this helps