简体   繁体   中英

Deploying to heroku changing DEBUG = False results in 500 error

Im using Django 1.9 and Python 3.4.3 . When changing DEBUG = False on my app I'm getting a 500 error on all pages of my app.

Note: The Django admin page results in a 500 error as well. Some other posts reported not getting this error on the admin page and I am. I have also tried everything in this post

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

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

STATIC_URL = '/static/'

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

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

MEDIA_URL = '/media/'

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

It will be better if you add the ADMINS to the settings:

ADMINS = (('Your name', 'Your@EMAIL'),)

With that you'll receive a better report when the error occur that you can use to debug the error.

Hope it helps

Whitenoise is looking for something it can't find. I had a problem with this as well and never got it working. Depending on how many static files you have, decide if you really need to cache them.

If you don't, just leave it out.
If you do, you need to find what it is whitenoise is trying to find and give it that. Maybe this helps: https://stackoverflow.com/a/28385055/1322179

You may have forgotten to include the whitenoice middleware in your settings.py MIDDLEWARE setting. Edit your settings.py file and add WhiteNoise to the MIDDLEWARE_CLASSES list, above all other middleware apart from Django's SecurityMiddleware:

MIDDLEWARE_CLASSES = [
# 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
#...
]

This is NOT necessary when DEBUG=True but when DEBUG=False, suddenly you have an issue. Heroku unfortunately don't include this middleware addition in their documentation and their demo apps run in DEBUG=True, so it's tough to find the issue.

More information can be found in the whitenoise docs: http://whitenoise.evans.io/en/stable/django.html

Go through the step-by-step setup to see what you're missing. The Heroku docs tend to omit the middleware addition--which causes the bug--and perhaps there's something else missing for your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM