0

I am deploying my Django application to Railway.

I am following this guide, https://docs.djangoproject.com/en/4.2/howto/static-files/deployment/#how-to-deploy-static-files. The app was deployed successfully but cannot load the static files. I followed some online tutorials on this and it is still not working. What did I miss?

My Railway deploy log:

Not Found: /static/styles/style.css
Not Found: /static/images/logo.svg
Not Found: /static/styles/style.css
Not Found: /static/images/logo.svg
Not Found: /static/images/avatar.svg
Not Found: /static/images/avatar.svg
Not Found: /static/js/script.js
Not Found: /static/js/script.js

settings.py:

DEBUG = False

STATIC_ROOT = BASE_DIR / "staticfiles"

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    BASE_DIR / "static",
]

MEDIA_URL = '/images/'

MEDIA_ROOT = BASE_DIR / 'static/images'
jethro-dev
  • 249
  • 1
  • 5
  • 12

1 Answers1

1

It's better to serve the static files through Nginx instead of django.

Do the following steps

  1. Collect static files
    python manage.py collectstatic
    
  2. Update nginx config to serve the static files
    location /static/ {
        root /path/to/staticfiles;
    }
    

It will work like below Browser [request]--> Nginx [static files]

anjaneyulubatta505
  • 10,713
  • 1
  • 52
  • 62