Django app only works on Debug=True Heroku

I thought I had this solved but I guess not. I've got my Django app on Heroku, and it works perfectly with DEBUG = True but does not work with DEBUG = False.

UPDATED QUESTION

Now I'm just battling with this error:

2018-03-14T18:42:08.812921+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=www.powertranspro.com request_id=f75a1cec-d303-4f5c-8eee-ddf605b7c326 fwd="71.38.218.24" dyno=web.1 connect=0ms service=30001ms status=503 bytes=0 protocol=http

Would someone mind reviewing my settings files to see where I've gone wrong.

First my file structure:

enter image description here

base.py

# settings/base.py

import os
from django.utils import timezone
import dj_database_url
from decouple import config
from .aws.conf import *

DEBUG = config('DEBUG', cast=bool)
GOOGLE_MAPS_API_KEY = config('GOOGLE_MAPS_API_KEY')
EASY_MAPS_GOOGLE_MAPS_API_KEY = config('GOOGLE_MAPS_API_KEY')


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

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Application definition

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATES_DIR],
        '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',
                'apps.todos.context_processors.todos_processor',
                'apps.freight_projects.context_processors.freight_projects_processor',
            ],
            'debug': DEBUG,
        },
    },
]

INSTALLED_APPS = [
    'dal',
    'dal_select2',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.sites',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'django_misaka',
    'bootstrap3',
    'localflavor',
    'easy_pdf',
    'django_google_maps',
    'easy_maps',
    'django_celery_beat',
    'django_celery_results',
    'celerybeat_status',
    'widget_tweaks',
    'storages',
    # django-allauth
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
    'allauth.socialaccount.providers.linkedin',
    # end django all-auth
    # my created apps
    'apps.accounts',
    'apps.user_dashboard',
    'apps.customer_dashboard',
    'apps.freight_projects',
    'apps.todos',
    'apps.locations',
    'apps.loads',
    'apps.project_template_tags',
    'apps.quotes',
    # end my created apps
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

ROOT_URLCONF = 'config.urls'

# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.django.DjangoTemplates',
#         'DIRS': [TEMPLATE_DIR],
#         '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',
#                 'apps.todos.context_processors.todos_processor',
#                 'apps.freight_projects.context_processors.freight_projects_processor',
#             ],
#
#         },
#     },
# ]

WSGI_APPLICATION = 'config.wsgi.application'

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

AUTHENTICATION_BACKENDS = (
    # Needed to login by username in Django admin, regardless of `allauth`
    'django.contrib.auth.backends.ModelBackend',
)
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Change 'default' database configuration with $DATABASE_URL.
#DATABASES['default'].update(dj_database_url.config(conn_max_age=500))

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers


SITE_ID = 1
LOGIN_REDIRECT_URL = 'login_success'
LOGOUT_REDIRECT_URL = 'logout_confirmation'

# MEDIA_URL = '/media/'
# MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Brought this over from aws.conf.py
# ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

#MAILGUN SETTINGS
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = config('EMAIL_PORT', cast=int)
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = config('EMAIL_USE_TLS', cast=bool)

AUTH_USER_MODEL = 'accounts.User'

ADMINS = (('Kris Tryber', 'kris@poweronlytransit.com'),)

production.py

   # settings/production.py
from .base import *
import os
from decouple import config
import dj_database_url
import django_heroku

DEBUG = config('DEBUG', cast=bool)

GOOGLE_MAPS_API_KEY = config('GOOGLE_MAPS_API_KEY')

SECRET_KEY = config('SECRET_KEY')


ALLOWED_HOSTS = ['shielded-tundra-23748.herokuapp.com']

DATABASES = {
    'default': dj_database_url.config(
        default=config('DATABASE_URL')
    )
}


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

# Configure Django App for Heroku.
import django_heroku
django_heroku.settings(locals())

CELERY_BROKER_URL=os.environ['REDIS_URL']
CELERY_RESULT_BACKEND=os.environ['REDIS_URL']

CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = TIME_ZONE

HEROKU LOGS

2018-03-13T21:53:23.232139+00:00 app[web.1]: [2018-03-13 21:53:23 +0000] [4] [INFO] Handling signal: term
2018-03-13T21:53:23.234260+00:00 app[web.1]: [2018-03-13 21:53:23 +0000] [9] [INFO] Worker exiting (pid: 9)
2018-03-13T21:53:23.236062+00:00 app[web.1]: [2018-03-13 21:53:23 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-03-13T21:53:23.543646+00:00 heroku[beat.1]: Stopping all processes with SIGTERM
2018-03-13T21:53:23.575710+00:00 heroku[worker.1]: Stopping all processes with SIGTERM
2018-03-13T21:53:23.591368+00:00 app[worker.1]: 
2018-03-13T21:53:23.591399+00:00 app[worker.1]: worker: Warm shutdown (MainProcess)
2018-03-13T21:53:23.749154+00:00 app[web.1]: [2018-03-13 21:53:23 +0000] [4] [INFO] Shutting down: Master
2018-03-13T21:53:24.012876+00:00 heroku[beat.1]: Process exited with status 0
2018-03-13T21:53:24.023046+00:00 heroku[web.1]: Process exited with status 0
2018-03-13T21:53:25.509937+00:00 heroku[worker.1]: Process exited with status 0
2018-03-13T21:53:43.386916+00:00 heroku[worker.1]: Starting process with command `celery -A config worker --beat`
2018-03-13T21:53:44.117616+00:00 heroku[worker.1]: State changed from starting to up
2018-03-13T21:53:45.218810+00:00 heroku[beat.1]: Starting process with command `celery -A config beat -S django`
2018-03-13T21:53:45.731767+00:00 app[worker.1]: ['/app/config/static']
2018-03-13T21:53:46.053233+00:00 heroku[beat.1]: State changed from starting to up
2018-03-13T21:53:46.582872+00:00 heroku[web.1]: Starting process with command `gunicorn config.wsgi --log-file -`
2018-03-13T21:53:47.349183+00:00 app[worker.1]:  
2018-03-13T21:53:47.349228+00:00 app[worker.1]:  -------------- celery@b0aaf05c-7b04-4327-9e0c-10c3fe7f2965 v4.1.0 (latentcall)
2018-03-13T21:53:47.349231+00:00 app[worker.1]: ---- **** ----- 
2018-03-13T21:53:47.349234+00:00 app[worker.1]: --- * ***  * -- Linux-4.4.0-1012-aws-x86_64-with-debian-stretch-sid 2018-03-13 21:53:47
2018-03-13T21:53:47.349236+00:00 app[worker.1]: -- * - **** --- 
2018-03-13T21:53:47.349237+00:00 app[worker.1]: - ** ---------- [config]
2018-03-13T21:53:47.349240+00:00 app[worker.1]: - ** ---------- .> app:         POTRTMS:0x7f638769d7b8
2018-03-13T21:53:47.349241+00:00 app[worker.1]: - ** ---------- .> transport:   redis://h:**@ec2-34-239-77-182.compute-1.amazonaws.com:53459//
2018-03-13T21:53:47.349243+00:00 app[worker.1]: - ** ---------- .> results:     redis://h:**@ec2-34-239-77-182.compute-1.amazonaws.com:53459/
2018-03-13T21:53:47.349246+00:00 app[worker.1]: - *** --- * --- .> concurrency: 8 (prefork)
2018-03-13T21:53:47.349247+00:00 app[worker.1]: -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
2018-03-13T21:53:47.349249+00:00 app[worker.1]: --- ***** ----- 
2018-03-13T21:53:47.349250+00:00 app[worker.1]:  -------------- [queues]
2018-03-13T21:53:47.349252+00:00 app[worker.1]:                 .> celery           exchange=celery(direct) key=celery
2018-03-13T21:53:47.349254+00:00 app[worker.1]:                 
2018-03-13T21:53:47.349262+00:00 app[worker.1]: 
2018-03-13T21:53:47.860250+00:00 app[beat.1]: ['/app/config/static']
2018-03-13T21:53:47.881589+00:00 app[beat.1]: celery beat v4.1.0 (latentcall) is starting.
2018-03-13T21:53:49.678712+00:00 app[beat.1]: __    -    ... __   -        _
2018-03-13T21:53:49.678762+00:00 app[beat.1]: LocalTime -> 2018-03-13 21:53:49
2018-03-13T21:53:49.678765+00:00 app[beat.1]: Configuration ->
2018-03-13T21:53:49.678767+00:00 app[beat.1]:     . broker -> redis://h:**@ec2-34-239-77-182.compute-1.amazonaws.com:53459//
2018-03-13T21:53:49.678769+00:00 app[beat.1]:     . loader -> celery.loaders.app.AppLoader
2018-03-13T21:53:49.678771+00:00 app[beat.1]:     . scheduler -> django_celery_beat.schedulers.DatabaseScheduler
2018-03-13T21:53:49.678773+00:00 app[beat.1]: 
2018-03-13T21:53:49.678774+00:00 app[beat.1]:     . logfile -> [stderr]@%WARNING
2018-03-13T21:53:49.678776+00:00 app[beat.1]:     . maxinterval -> 5.00 seconds (5s)
2018-03-13T21:53:49.884036+00:00 app[web.1]: [2018-03-13 21:53:49 +0000] [4] [INFO] Starting gunicorn 19.7.1
2018-03-13T21:53:49.884609+00:00 app[web.1]: [2018-03-13 21:53:49 +0000] [4] [INFO] Listening at: http://0.0.0.0:15685 (4)
2018-03-13T21:53:49.884728+00:00 app[web.1]: [2018-03-13 21:53:49 +0000] [4] [INFO] Using worker: sync
2018-03-13T21:53:49.889062+00:00 app[web.1]: [2018-03-13 21:53:49 +0000] [8] [INFO] Booting worker with pid: 8
2018-03-13T21:53:49.892636+00:00 app[web.1]: [2018-03-13 21:53:49 +0000] [9] [INFO] Booting worker with pid: 9
2018-03-13T21:53:50.816149+00:00 heroku[web.1]: State changed from starting to up
2018-03-13T21:53:51.040875+00:00 app[web.1]: ['/app/config/static']
2018-03-13T21:53:51.180555+00:00 app[web.1]: ['/app/config/static']
2018-03-13T21:53:25+00:00 app[heroku-redis]: source=REDIS sample#active-connections=1 sample#load-avg-1m=0.08 sample#load-avg-5m=0.13 sample#load-avg-15m=0.125 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15664184kB sample#memory-free=12008784kB sample#memory-cached=1496784kB sample#memory-redis=312336bytes sample#hit-rate=0.41381 sample#evicted-keys=0
2018-03-13T21:54:20.036317+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:8)
2018-03-13T21:54:20.036666+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:9)
2018-03-13T21:54:20.037926+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-03-13T21:54:20.038168+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [9] [INFO] Worker exiting (pid: 9)
2018-03-13T21:54:20.337323+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [12] [INFO] Booting worker with pid: 12
2018-03-13T21:54:20.438551+00:00 app[web.1]: [2018-03-13 21:54:20 +0000] [14] [INFO] Booting worker with pid: 14
2018-03-13T21:54:20.966862+00:00 app[web.1]: ['/app/config/static']
2018-03-13T21:54:21.114239+00:00 app[web.1]: ['/app/config/static']
2018-03-13T21:54:23.414661+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/loads/load_list/filter/" host=www.powertranspro.com request_id=912215ee-893e-431a-8849-a6cb0195ade8 fwd="71.38.218.24" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=http

Traceback

Traceback:

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  158.                 response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  156.                 response = response.render()

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/response.py" in rendered_content
  83.         content = template.render(context, self._request)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  175.                     return self._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  155.             return compiled_parent._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
  155.             return compiled_parent._render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
  167.         return self.nodelist.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
  943.                 bit = node.render_annotated(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
  910.             return self.render(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py" in render
  106.         url = self.url(context)

File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py" in url
  103.         return self.handle_simple(path)

File "/app/.heroku/python/lib/python3.6/site-packages/django/templatetags/static.py" in handle_simple
  118.             return staticfiles_storage.url(path)

File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py" in url
  155.         return self._url(self.stored_name, name, force)

File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py" in _url
  134.                 hashed_name = hashed_name_func(*args)

File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py" in stored_name
  422.                 raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)

Exception Type: ValueError at /loads/load_list/filter/
Exception Value: Missing staticfiles manifest entry for 'vendors/bootstrap/dist/css/bootstrap.min.css'
Request information:

2 answers

  • answered 2018-03-13 21:18 Aokiji

    From the Whitenoise Docs:

    If you’re having problems with the WhiteNoise storage backend, the chances are they’re due to the underlying Django storage engine. This is because WhiteNoise only adds a thin wrapper around Django’s storage to add compression support, and because the compression code is very simple it generally doesn’t cause problems.

    The most common issue is that there are CSS files which reference other files (usually images or fonts) which don’t exist at that specified path. When Django attempts to rewrite these references it looks for the corresponding file and throws an error if it can’t find it.

    To test whether the problems are due to WhiteNoise or not, try swapping the WhiteNoise storage backend for the Django one:

    STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
    

    Also try python manage.py collectstatic and check if the problem still occurs.

  • answered 2018-03-13 21:18 joshlsullivan

    In your project directory, where manage.py is located, will you add a static folder and put a blank human.txt file inside of it? Then do a git commit and push.

    enter image description here