Railway volumes in Django not working as expected

codelover
PRO

2 years ago

Hello! I added a Volume to my Django project on Railway for persistent storage of PDF-Generated files. I set the mount path to /media. From what I read, there will be a media folder in the base directory (or maybe I need to create one if it does not exist) where the data will be persisted. However when I deploy changes all the files are lost. When I try to access a file using os.path.join('media', 'hello.pdf') I get a file does not exist error. I don't know if I am missing something.

0 Replies

codelover
PRO

2 years ago

Project id is: 98888b3e-8302-4a34-a31a-6ba9963dccee


2 years ago

your paths are incorrect, please give the guide a read


codelover
PRO

2 years ago

Alright. I'll read the guid and I'll be right back


codelover
PRO

2 years ago

Thank you very much. After reading the guid carefully, I realized you were right about paths being incorrect. Indeed, I thought the media directory would be created inside my Django project directory, but it was one level up my directory, so I had to use the ../media relative path to access the volume storage directory. I tried to deploy some changes and the files are still accessible. Thank you


2 years ago

you can use the media path like you where, but instead set the mount to /app/media
this is what i had hoped you would take away from the docs page


codelover
PRO

2 years ago

Ok. I'll try that, too. Thanks


codelover
PRO

2 years ago

It works too.


2 years ago

awsome


Railway volumes in Django not working as expected - Railway Help Station