I am running Django on Heroku. I can successfully run collectstatic, but when I go to the site it is obvious that Django is unable to find my static files. Here’s a snippet from my settings — I think it’s mostly standard stuff:
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_DIR, 'static'),
)
# List of finder classes that know how to find static files in
# various locations.
if CLAYS_ENV == 'dev':
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
And in my case the CLAYS_ENV variable will be set to ‘dev’. Any ideas on why Django can successfully run collectstatic, but then can’t find the files afterwards?
It’s recommended to serve static files through a CDN (like Amazon S3) when using Heroku. While you can still manage to serve those directly from Heroku, the same process attending dynamic requests is also serving static data, wasting processing time. Also, in case of media files, the use of a CDN is mandatory, since Heroku’s file-system is “ephimeral”: Every time you deploy new code, a new image of the Cedar stack is recreated from scratch and a new code checkout is made. Every file not Git-tracked created between deploys is lost.