1

My Djangoproject call: myDebug and my Django app call: Deb

it is on Heroku: meindebug.herokuapp.com

settings.py

import os
import django_heroku 

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))



SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'


DEBUG = False


ALLOWED_HOSTS = ['meindebug.herokuapp.com']

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

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',
    'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'myDebug.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 = 'myDebug.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


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


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/2.0/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

django_heroku.settings(locals())

!!! please notice i tried it with ALLOWED_HOSTS = ['*'] but nothing changed !!!

wsgi.py

import os

from django.core.wsgi import get_wsgi_application
from whitenoise import WhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myDebug.settings")

application = get_wsgi_application()
application = WhiteNoise(application, root='/static/Deb/Images/')
application.add_files('/static/Deb/Images/', prefix='more-files/')

Procfile

web: gunicorn myDebug.wsgi 

Pipfile

[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]
gunicorn = "*"
django-heroku = "*"
whitenoise = "*"

[dev-packages]

[requires]
python_version = "3.6"

Since two Weeks i tried to fix that issue. Unfortunately, I was not successful.

Nowhere i find a real Fix. Only some words there and there but noone have a real Solution.

  • What does your Gunicorn log show when you deploy with `debug=False`? Also, you should probably remove your `SECRET_KEY` value from your post... – tatlar Apr 16 '18 at 19:56
  • 1
    This could be caused by your `MIDDLEWARE` order, [WhiteNoise documentation](http://whitenoise.evans.io/en/stable/django.html#enable-whitenoise) states that `'whitenoise.middleware.WhiteNoiseMiddleware'` should placed be immediately after `'django.middleware.security.SecurityMiddleware'`. – rafalmp Apr 16 '18 at 19:56
  • @rafalmp i changed the order but nothing changed – Florian Buchfink Apr 16 '18 at 20:15
  • @tatlar where i can see the Gunicorn log? – Florian Buchfink Apr 16 '18 at 20:16
  • Use the `heroku logs` command. See the [documentation](https://devcenter.heroku.com/articles/logging) for more info. – tatlar Apr 16 '18 at 23:17
  • Have you seen this [SO](https://stackoverflow.com/questions/28354179/why-would-django-fail-with-server-500-only-when-debug-false-and-db-is-set-to-pro/28385055#28385055) question/answer? – tatlar Apr 16 '18 at 23:44
  • Also [this one](https://stackoverflow.com/questions/34144009/deploying-to-heroku-changing-debug-false-results-in-500-error). Sounds like an issue with `staticfiles`? – tatlar Apr 16 '18 at 23:44
  • @tatlar : Internal Server Error: / ValueError at / Missing staticfiles manifest entry for '/Deb/Images/BLogoXSKopie.ico' – Florian Buchfink Apr 17 '18 at 09:18
  • Have you run `python manage.py collectstatic` on the Heroku box? Also, check out this [SO](https://stackoverflow.com/questions/26829435/collectstatic-command-fails-when-whitenoise-is-enabled/32347324#32347324) question/answer – tatlar Apr 17 '18 at 16:20

3 Answers3

1

First you have to run python manage.py collectstatic. Then in Heroku the Config Variables to COLLECTSTATIC = 1.

but the file Path to your Pictures/Files have to show like this

{% static "MyApp/Images/Picture.png" %}

you get an Error if you write it so

 {% static "/MyApp/Images/Picture.png" %}

the slash at front of MyApp is the problem. So write it without slash then it works.

If you have a favicon in the head then you have to write it so

<link rel="shortcut icon" href="https://www.yourwebsite.de/static/MyApp/Images/favicon.ico">
1

For what it's worth, you'll face the same issue if you have an html comment in your code that calls the template tag "static" (probably the behavior is the same for every commented template tag), this was my case:

<!-- <img  src="{% static 'main_website/images/image.jpg' %}" alt=""> -->

removing the comment resoled the 500 error (which also, was not being logged).

Marcox
  • 102
  • 10
0

I had a same issue it appears that I had some css file linked but the original files were deleted. please make sure you aren't linking any not existing external file.