0
votes

I have developed my web application in Django Framework. I have also made the 404 and 500 Error pages and understand very much that, they can only work when DEBUG=False.

The problem now is that after setting DEBUG=False, my application which I have hosted on Heroku no longer shows. I am also using the whitenoise package for configuring my static files.

This are my settings.py as related to this issue

DEBUG = True

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

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

STATIC_URL = '/static/'
STATIC_ROOT = 'staticfile'
STATICFILES_DIRS = [BASE_DIR / "static"]
MEDIA_URL = '/media/'
MEDIA_ROOT = "media" 

NOTE: I have collected staticfiles using the command heroku run python manage.py collectstaic

1
Have you set the error handlers in urls.py file? - Ajay Lingayat
error handlers like how. How will i go about it please - coderboy
I mean have you created the views for rendering the error templates and called them through urls? - Ajay Lingayat
of course, i did. It worked perfectly when on local server but doesn't work and displays error "contact administartor and so so so". but i noticed the error only when I use the whitenoise in serving the static files and turning DEBUG=False - coderboy

1 Answers

0
votes

I was able to solve the issue. When I removed the whitenoise STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage', I noticed that i no longer got the error which read contact the administartor, and also my page was able to load and the 404 and 500 pages were loading correctly when i set the DEBUG=False

But I noticed that, the images where no longer showing. But I have a feeling that if I use aaws or cloudinary to host the images as well as server them, it should work perfectly.