R
Railway7mo ago
Jackson

Django (Wagtail) Media Files

Id: ee4f252f-387a-4b2c-999a-0af6f926854e I am having trouble setting up a volume to serve the media files uploaded by a Wagtail admin user. The PostgreSQL database template comes with a volume 'pgdata' by default. I tried attaching another volume to my production service called 'media' with path '/media/' as well as '/app/media/'. Neither worked. I even tried setting the MEDIA_URL to the database's PGDATA variable which is 'var/lib/postgresql/pgdata/' I know I am missing something. Thanks!
Solution:
but have a look at this template https://railway.app/template/AWUIv6
Jump to solution
9 Replies
Percy
Percy7mo ago
Project ID: ee4f252f-387a-4b2c-999a-0af6f926854e
Brody
Brody7mo ago
not sure why you are messing with postgres for media stuff?
Solution
Brody
Brody7mo ago
but have a look at this template https://railway.app/template/AWUIv6
Jackson
Jackson7mo ago
I tried it after the server's attached volume didn't work. Thought maybe the volume attached to the database was the place. I've already visited that resource. I'll try the 'Troubleshooting' section though. I have yet to try making a new directory.
Brody
Brody7mo ago
please also review its code specifically the urls.py
Jackson
Jackson7mo ago
Thanks. I wouldn't have thought to look at the repo. I'm deploying with new settings and urls now That was it! In settings set MEDIA_URL to RAILWAY_VOLUME_MOUNT_PATH and in urls.py set urlpatterns += [ re_path(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]
Brody
Brody7mo ago
awesome
Jackson
Jackson7mo ago
Thank you. That saved me a lot of time
Brody
Brody7mo ago
haha vin wrote the code not me