DEV Community

Cover image for Using staticfiles in a Django app deployed on Railway
Davide Fiorini
Davide Fiorini

Posted on

Using staticfiles in a Django app deployed on Railway

Are you trying to use static files in your Django project deployed on Railway platform?

I make this guide not only for myself (yeah I have a not-so-good memory and keeping here my notes could be a good choice where I can check anytime I stuck in some problem), but for everyone else as well that are not able to deploy their Django app, so here I wrote a list of good actions to follow in order deploy the app.
This guide is valid either you have DEBUG=False or DEBUG=True.

Sooo now pay attention to these steps in order not to run into an error:

  1. Keep watching on this template startCommand command at https://github.com/railwayapp-templates/django/blob/main/railway.json
    that has the same content that has to be used in our Procfile
    and https://github.com/railwayapp-templates/django/blob/main/mysite/settings.py
    which may have new settings to add to our settings.py.

  2. Keep track of the latest whitenoise docs at: https://whitenoise.readthedocs.io/en/latest/django.html

  3. Keep watching also of the official docs for further or new explanations at:
    https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Deployment

  4. Make sure there is command collectstatic inside the Procfile or deploy command section of Railway settings app.

  5. Make sure that on Railway settings of the app there is no Deploy -> Start Command set value since there is already inside the Procfile or viceversa.

  6. Make sure that on Railway settings of the app there is the correct path / or subpath /... at General -> Root Directory set.

  7. Make sure that requirements.txt, Procfile and runtime.txt are in the same folder of the Django manage.py file.

  8. Make sure that inside Procfile there is the right myapp.wsgi command text.

Ok that's all folks, have a nice coding!

Top comments (0)