Please my images are not displaying after deploying on railway. I am new in web development.
Please I am new to web development and first time deploying to railway. I have django drf backend with react.js frontend. My images are not displaying when i deploy it on railway. Please any help
17 Replies
Project ID:
N/A
N/A
hi
are you using a custom dockerfile
No please, the deployment is done through github and is handle by railway.
do they display locally
yes...when i use Debug= True, in my localhost, everything works well. but when i deploy to railway, the media links is 404
I've literally just solved this exact problem in the last hour
are you using volumes?
No Please, I am not using volumes. I am new to web development and my first time of using railway. Any help is welcome
The link I sent you shows how to set up a volume
Just set that up and then I'll tell you what to change in your Django project
I have created the volume and attach it to my django project
Ok, now you need to no to back to your Dango project and change the settings
MEDIA_URL = 'media/'
MEDIA_ROOT = os.environ["RAILWAY_VOLUME_MOUNT_PATH"]
You've probably got something like this in your urls.py file to serve your media files locally:
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
change it to this:
urlpatterns = [
# ... the rest of your URLconf goes here ...
] + [ re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]
The last thing to do is go to your newly created volume and change the mount path to "/app/media" or whatever you want to call that folder
Then it should workPlease I am having error with the MEDIA_ROOT = os.environ["/media"] line of code in my settings. any help
Media root is this:
MEDIA_ROOT = os.environ["RAILWAY_VOLUME_MOUNT_PATH"]
import os (if you haven't already)
just use the environment variable that Railway gives you
Anyway, good luck with this. I'm logging offit didn't work or maybe I couldn't configure it well.
You need to make sure that the
MEDIA_ROOT
and MEDIA_URL
are configured properly
As well as that urlpatterns
list
Just double check them
Also, make sure that your volume is actually working ie. that the usage is going up when you try to upload something. You can see that in the metrics