Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Django generate HTTP 500 errors for static media when Debug is set to False?

I'm preparing to deploy my Django app and I noticed that when I change the "DEBUG" setting to False, all references to static files (i.e., JavaScript, CSS, etc..) result in HTTP 500 errors.

Any idea what's causing that issue (and how to fix it)?

like image 865
Huuuze Avatar asked Sep 23 '08 15:09

Huuuze


2 Answers

I would highly recommend letting your web server handle the static requests, without getting to Django. In my urls.py, I only add the static request handler when debug is set to True.

Technically, Django serving the static works fine though. Definitely read the short docs page, http://docs.djangoproject.com/en/dev/howto/static-files/. You'll want to use an entry like this in urls.py

(r'^static/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': '/path/to/media'})
like image 92
Peter Shinners Avatar answered Nov 15 '22 08:11

Peter Shinners


It sounds like you might be trying to serve your static media using the Django development server. Take a look at http://docs.djangoproject.com/en/dev/howto/deployment/ for some deployment scenarios/howtos and http://docs.djangoproject.com/en/dev/howto/static-files/ for how to serve static files (but note the disclaimer about NOT using those methods in production).

In general, I'd look at your server logs and see where it's trying to fetch the files from. I suspect the 500 errors are really 404 errors, but they become 500 errors because Django can't find or render the 404.html template. If that's not the case, it would be helpful if you could post the specific 500 error you're getting.

like image 25
Kevin Avatar answered Nov 15 '22 07:11

Kevin