Question

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)?

Was it helpful?

Solution

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'})

OTHER TIPS

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.

You must also check your URLs all over the place. When the DEBUG is set to False, all URLs without trailing "/" are treated as a bug, unlike when you have DEBUG = True, in which case Django will append "/" everywhere it is missing. So, in short, make sure all links end with a slash EVERYWHERE.

Turns out I'd commented out the SECRET_KEY variable. There was no way for me to know though. Just had to try things out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top