R
Railway10mo ago
joe227

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
Percy
Percy10mo ago
Project ID: N/A
joe227
joe22710mo ago
N/A
josh
josh10mo ago
hi are you using a custom dockerfile
joe227
joe22710mo ago
No please, the deployment is done through github and is handle by railway.
josh
josh10mo ago
do they display locally
joe227
joe22710mo ago
yes...when i use Debug= True, in my localhost, everything works well. but when i deploy to railway, the media links is 404
Iceman
Iceman10mo ago
I've literally just solved this exact problem in the last hour are you using volumes?
Iceman
Iceman10mo ago
joe227
joe22710mo ago
No Please, I am not using volumes. I am new to web development and my first time of using railway. Any help is welcome
Iceman
Iceman10mo ago
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
joe227
joe22710mo ago
I have created the volume and attach it to my django project
Iceman
Iceman10mo ago
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 work
joe227
joe22710mo ago
Please I am having error with the MEDIA_ROOT = os.environ["/media"] line of code in my settings. any help
Iceman
Iceman10mo ago
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 off
joe227
joe22710mo ago
it didn't work or maybe I couldn't configure it well.
Iceman
Iceman10mo ago
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