djangodjango-staticfiles

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


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

Solution

  • WhiteNoise work for me:

    pip install whitenoise
    

    In your settigs.py:

    INSTALLED_APPS = [
        'django.contrib.staticfiles',
        'whitenoise.runserver_nostatic',    
    ]
    
    MIDDLEWARE = [
        "django.middleware.security.SecurityMiddleware",
        "whitenoise.middleware.WhiteNoiseMiddleware",
    ]
    
    STATIC_URL = '/static/'
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    STATICFILES_STORAGE="whitenoise.storage.CompressedManifestStaticFilesStorage"