UncompressableFileError When Deploy Django Project on Heroku
I was using Django as my website backend framework, and it was my first time to do the backend stuff myself. After some days ramp up and search, I found the Cookiecutter Django provides a very good project template which could be used in a production level.
Few days struggling, I finally get into the last deployment step. I followed the document to deploy the website on Heroku.
However, after I got an error, the website shows “Internal Service Error” and opbeat send me this error:
UncompressableFileError: ‘https://s3.amazonaws.com:443/*bucket-name*/static/css/project.css' isn’t accessible via COMPRESS_URL (‘https://s3.amazonaws.com/*bucket-name*/static/') and can’t be compressed.
However, I was able to open the project.css directly in the browser, how come I don’t have access to the directory?
It took me hours to search and I still couldn’t figure it out. Then I decided to look into the source code and found this:
1 | if not url.startswith(base_url): |
Comparing to the error I received, we could conclude that:
- url: https://s3.amazonaws.com:443/*bucket-name*/static/css/project.css
- base_url: https://s3.amazonaws.com/*bucket-name*/static/
Found the difference?
YEP, the base_url missing the port number!
Because in the source code, the Python code used url.startswith() method, thus the url should be exactly match!
So in the production.py file modify the STATIC_URL as following:
1 | STATIC_URL = 'https://s3.amazonaws.com:443/%s/static/' % AWS_STORAGE_BUCKET_NAME |
Commit the change, the website is alive!