4

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')
Community
  • 1
  • 1
Groovietunes
  • 633
  • 1
  • 9
  • 17
  • What does the apache log say the error actually is? – markwalker_ Dec 07 '15 at 22:11
  • @marksweb I edited the logs into the question its not saying much – Groovietunes Dec 07 '15 at 22:19
  • Can you post what heroku responses with when you `push` your app? I bet something is getting confused with your static files and and the app isn't actually being deployed. – Ben Dec 07 '15 at 22:40
  • @Ben sure thing. I appended it to the end of the logs – Groovietunes Dec 07 '15 at 22:49
  • Did you run the command they recommend? `heroku run python manage.py collectstatic --noinput` – Ben Dec 07 '15 at 23:10
  • Ah I just saw you have `whitenoise` in your app. I've never gotten this to work. comment it out and re run, see if that fixes it – Ben Dec 07 '15 at 23:13
  • @Ben dude! it worked kinda. Thank you! So......how do suggest loading static files now? Because they are not loading in. – Groovietunes Dec 07 '15 at 23:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97240/discussion-between-ben-and-groovietunes). – Ben Dec 07 '15 at 23:30

3 Answers3

3

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

ddalu5
  • 401
  • 4
  • 17
  • @groovietunes With admins set you will receive an email with the traceback that you would normally see when `DEBUG=True`. – Ben Dec 07 '15 at 22:37
  • @Ben Thanks for the suggestion I added the traceback results to the end of the question. I'm starting to get the impression that maybe my staticfiles arnt configured properly for production but that does not make sense as to why i'm getting a 500 error – Groovietunes Dec 07 '15 at 22:58
3

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.

user1847
  • 3,571
  • 1
  • 26
  • 35
2

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

Community
  • 1
  • 1
Ben
  • 6,986
  • 6
  • 44
  • 71