R
Railwayβ€’2mo ago
isabelle

Volumes and Django

Hi there! I am a little stuck on something probably quite simple. It is my first Django deployment. My files locally live in a folder called /media/ that I do not include in the repo (it is in .gitignore). Now it is time to put in prod and I made a volume on Railway (path: '/media'). Two problems: 1. How can I copy my old media files over? 2. I tried to manually upload new files and it doesn't seem to be working, I'm guessing my path is wrong? Here is what my settings looks like: MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_URL = "/media/" It's a bit urgent so if you know the answer and can help it would be soooo appreciated πŸ™‚ Thanks!
69 Replies
Percy
Percyβ€’2mo ago
Project ID: 44d106ae-9c5c-4d81-86b3-296c53f1efee
isabelle
isabelleOPβ€’2mo ago
44d106ae-9c5c-4d81-86b3-296c53f1efee
Brody
Brodyβ€’2mo ago
what is the mount path of the volume?
isabelle
isabelleOPβ€’2mo ago
/media is what i've put
isabelle
isabelleOPβ€’2mo ago
No description
Brody
Brodyβ€’2mo ago
Dockerfile or nixpacks?
isabelle
isabelleOPβ€’2mo ago
whatever was default set up im not sure
Brody
Brodyβ€’2mo ago
then nixpacks
isabelle
isabelleOPβ€’2mo ago
in the build logs it menions docker
Brody
Brodyβ€’2mo ago
isabelle
isabelleOPβ€’2mo ago
I already have, but I am confused :S
Brody
Brodyβ€’2mo ago
tl;dr mount to /app/media
isabelle
isabelleOPβ€’2mo ago
i set my django settings like this originally and the MEDIA_VOLUME_PATH does refer to /app/media (I set it in the env variables in prod): MEDIA_ROOT = os.getenv("MEDIA_VOLUME_PATH", os.path.join(BASE_DIR, "media")) MEDIA_URL = "/media/"
Brody
Brodyβ€’2mo ago
go back to the code you originally showed in the root post and update your mount path
isabelle
isabelleOPβ€’2mo ago
alright i can't seem to edit it
Brody
Brodyβ€’2mo ago
why not?
isabelle
isabelleOPβ€’2mo ago
the original post? dunno i click edit post and its the title
Brody
Brodyβ€’2mo ago
why do you need to edit your post?
isabelle
isabelleOPβ€’2mo ago
ohhh sorry i misunderstood you yes i ahve already changed it back in the code testing it now sorry i think i am confused MEDIA_ROOT = os.getenv("MEDIA_VOLUME_PATH", os.path.join(BASE_DIR, "media")) MEDIA_URL = "/media/" change this??
Brody
Brodyβ€’2mo ago
change that back to the code you showed in the original post and then update your volume's mount
isabelle
isabelleOPβ€’2mo ago
okay
isabelle
isabelleOPβ€’2mo ago
so this? and this:
No description
No description
Brody
Brodyβ€’2mo ago
looks fine at first glance let's see your urls.py file as well
isabelle
isabelleOPβ€’2mo ago
from django.contrib import admin
from django.urls import path, include, re_path
from wagtail.admin import urls as wagtailadmin_urls
from wagtail import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("home.urls")),
path("", include("blogs.urls")),
path("cms/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path(r'comments/', include('django_comments_xtd.urls')),
path("", include(wagtail_urls)),
] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
from django.contrib import admin
from django.urls import path, include, re_path
from wagtail.admin import urls as wagtailadmin_urls
from wagtail import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("home.urls")),
path("", include("blogs.urls")),
path("cms/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path(r'comments/', include('django_comments_xtd.urls')),
path("", include(wagtail_urls)),
] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
Brody
Brodyβ€’2mo ago
please enclose that in a code block edit the message please code block please
isabelle
isabelleOPβ€’2mo ago
my bad
Brody
Brodyβ€’2mo ago
looks fine to me
isabelle
isabelleOPβ€’2mo ago
it is as if when i make a new post it doesn't know where to save the photo. look what happens: this is a pic i just uploaded
No description
isabelle
isabelleOPβ€’2mo ago
similarly this is what my files look like in admin on django/wagtail
No description
Brody
Brodyβ€’2mo ago
what are their status codes?
isabelle
isabelleOPβ€’2mo ago
you mean when i clik? pae not found
Brody
Brodyβ€’2mo ago
status code please
isabelle
isabelleOPβ€’2mo ago
im sorry i don't know how tofind that can you direct me please?
Brody
Brodyβ€’2mo ago
sorry but that's outside of the realm of what we can help with
isabelle
isabelleOPβ€’2mo ago
okay
Brody
Brodyβ€’2mo ago
I'm just going to assume it's 404, meaning you need to fix your urls.py file
isabelle
isabelleOPβ€’2mo ago
ok is there an example online of what the setup should look like? i think it would help me, i couldn't find one
Brody
Brodyβ€’2mo ago
you've asked at a very bad time, the repo I would have sent has gone missing
isabelle
isabelleOPβ€’2mo ago
thats what i thought does this provide any info? https://web-production-2206.up.railway.app/media/images/bamies_main_photo_toijouv.original.jpg This is the URL that is given to the photoo when i upload it
Brody
Brodyβ€’2mo ago
I'm on mobile, so no what's your current volume mount
isabelle
isabelleOPβ€’2mo ago
/app/media
Brody
Brodyβ€’2mo ago
what's your media settings
isabelle
isabelleOPβ€’2mo ago
MEDIA_ROOT = os.getenv("RAILWAY_VOLUME_MOUNT_PATH", os.path.join(BASE_DIR, "media"))


MEDIA_URL = "/media/"
MEDIA_ROOT = os.getenv("RAILWAY_VOLUME_MOUNT_PATH", os.path.join(BASE_DIR, "media"))


MEDIA_URL = "/media/"
ive been trying different iterations of it
Brody
Brodyβ€’2mo ago
again, use the code you originally posted
isabelle
isabelleOPβ€’2mo ago
it doesn't work. it looks as though when you upload a photo it gets sent to the wrong place a folder that doesn't exist. are you sure /app/media doesn't need to be referenced?
Brody
Brodyβ€’2mo ago
what makes you say it's sent to the wrong location, does the volume's metrics increase?
isabelle
isabelleOPβ€’2mo ago
yes actaully i guess it is uploaded to the right volume but the website is not trying to pick it up from there? the url of the pic when i click on it is just 'media' not app/media also, changed it to the original code from the post and printed the MEDIA_ROOT and it gave '/media' is this right?
Brody
Brodyβ€’2mo ago
do you not have BASE_DIR defined?
isabelle
isabelleOPβ€’2mo ago
BASE_DIR = Path(__file__).resolve().parent.parent
Brody
Brodyβ€’2mo ago
why is that not printing anything?
isabelle
isabelleOPβ€’2mo ago
Can you help me with the other part of my question please? Basically, can i push my local media folder to the volume? like with scp or something?
Brody
Brodyβ€’2mo ago
it's complicated, it's best if you upload the media again
isabelle
isabelleOPβ€’2mo ago
okay i still haven't been able to get it to work. as far as i understnad the media_url is meant to be where i can find the files and i get "Page not found"
Brody
Brodyβ€’2mo ago
as mentioned, your urls.py is wrong you need something to actually serve the media files on that url path
isabelle
isabelleOPβ€’2mo ago
how can i do this? is there any more documentation on it
isabelle
isabelleOPβ€’2mo ago
so this is wrong?
No description
isabelle
isabelleOPβ€’2mo ago
you said it looked fine here
Brody
Brodyβ€’2mo ago
I'm not a Django developer this wouldn't be specific to railway
isabelle
isabelleOPβ€’2mo ago
but usually, for example if i was using google buckets, there would be information on how to serve it
Brody
Brodyβ€’2mo ago
right but you are serving from disk, so it's not platform specific
isabelle
isabelleOPβ€’2mo ago
okay is it true that: Railway handles this by default for you, so you usually don’t need to configure Nginx or other web servers manually. (from chat gpt) meaning if i remove that part from urls.py railway will just sort it for me?
Brody
Brodyβ€’2mo ago
no that's not true at all, this has nothing to do with the platform, your application needs to serve those media files itself
isabelle
isabelleOPβ€’2mo ago
is it better to not use railway volumes?
Brody
Brodyβ€’2mo ago
there's nothing wrong with using railway volume's, I strongly advise you not to ask AI about railway
isabelle
isabelleOPβ€’2mo ago
haha okay. look i'm a little confused there seems to be so little information on how to use this. what should the url look like?
Brody
Brodyβ€’2mo ago
since this is not platform related, I'm unsure why you're unable to find an answer to this on sites like stack overflow
isabelle
isabelleOPβ€’2mo ago
sorry i thought it was related to railway volumes. typically i would be able to find the answer in the documentation apologies
Brody
Brodyβ€’2mo ago
the mount point stuff was in the docs, but this has now become purely coding questions about django and for coding questions related to Django, railway's docs aren't going to help
Want results from more Discord servers?
Add your server