pythondjangodjango-templatesdjango-compressor

Django-Compress with debug=false in settings giving error


I am facing a weird problem in django. I am using django-compress app. Till debug is true everything goes all right. When I do debug=False, I face the internal server error problem in case of 404 and page without js and css in case of no 404. Worst part is, on console I am getting following error

UncompressableFileError: 'css/default.css' isn't accesible via COMPRESS_URL ('/static/') and can't be compressed [16/Jul/2012 17:17:05] "GET /static/img/favicon.ico HTTP/1.1" 500 59

Like this it shows 500 for every GET request which are accessible through /static/

So now reason for not getting js and css is clear. But reason for getting error on 404 page is not clear.

Even I tried it disabling and enabling django-compress, but on enabling even normal pages show 404 error

Please let me know what is causing 500 error for all /static/ things and why 404 page gives internal server error.


Solution

  • When DEBUG = True Django serves the static files. This means it can find the static files in the /static/ directories of each Django app. In turn, that means django-compressor can find each of the static files it needs to compress.

    When DEBUG = False Django no longer serves the static files but they should be served by the web server. It does this by serving all static files in the STATIC_ROOT directory (often /static/). That means all static files from the Django apps need to be put there.

    This can be done with the collectstatic command (see The staticfiles app in the Django documentation). After you have run that command all static files should be located in STATIC_ROOT and django-compressor should be able to find the files again. That solves the 404 errors you are getting with the static files and when django-compressor works you won't get the 500 errors anymore.