Railway.app can't find staticfiles after deployment django app

Viewed 28

I try to deploy my app to Railway.app. App generally works but static files are not found. I have made collectstatic folder using command django manage.py collectstatic as advised in deployment tutorials but it doesn't help. Any clue what could went wrong ?

settings.py

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

staticfiles folder is situated in directory that contains menage.py file

deploy logs from railway.apps

Not Found: /staticfiles/style.css
Not Found: /staticfiles/base.css
Not Found: /staticfiles/MyImage.png
Not Found: /staticfiles/base.js
1 Answers

I had similar issue, I think its a thing with Railway App, I ended up using Cloudinary to store my static files

pip install django-cloudinary-storage

Once you have done that, add cloudinary and cloudinary_storage to you installed apps in your settings.py. If you are going to use this package for static and/or media files, make sure that cloudinary_storage is before django.contrib.staticfiles:

INSTALLED_APPS = [
    # ...
    'cloudinary_storage',
    'django.contrib.staticfiles',
    'cloudinary',
    # ...
]

Next, you need to add Cloudinary credentials to settings.py:

CLOUDINARY_STORAGE = {
    'CLOUD_NAME': 'your_cloud_name',
    'API_KEY': 'your_api_key',
    'API_SECRET': 'your_api_secret'
}

Then run

python manage.py collectstatic --noinput
Related