9 months ago
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:
How can I copy my old media files over?
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:
MEDIAROOT = os.path.join(BASEDIR, "media")
MEDIA_URL = "/media/"
It's a bit urgent so if you know the answer and can help it would be soooo appreciated π Thanks!
0 Replies
9 months ago
44d106ae-9c5c-4d81-86b3-296c53f1efee
9 months ago
what is the mount path of the volume?
9 months ago
/media is what i've put
9 months ago
9 months ago
Dockerfile or nixpacks?
9 months ago
whatever was default set up
9 months ago
im not sure
9 months ago
then nixpacks
9 months ago
in the build logs it menions docker
9 months ago
please read this docs section -
9 months ago
I already have, but I am confused :S
9 months ago
tl;dr mount to /app/media
9 months ago
i set my django settings like this originally and the MEDIAVOLUMEPATH does refer to /app/media (I set it in the env variables in prod):
MEDIAROOT = os.getenv("MEDIAVOLUMEPATH", os.path.join(BASEDIR, "media"))
MEDIA_URL = "/media/"
9 months ago
go back to the code you originally showed in the root post
9 months ago
and update your mount path
9 months ago
alright
9 months ago
i can't seem to edit it
9 months ago
why not?
9 months ago
the original post?
9 months ago
dunno i click edit post and its the title
9 months ago
why do you need to edit your post?
9 months ago
ohhh sorry i misunderstood you
9 months ago
yes i ahve already changed it back in the code
9 months ago
testing it now
9 months ago
sorry i think i am confused
9 months ago
MEDIAROOT = os.getenv("MEDIAVOLUMEPATH", os.path.join(BASEDIR, "media"))
MEDIA_URL = "/media/"
change this??
9 months ago
change that back to the code you showed in the original post
9 months ago
and then update your volume's mount
9 months ago
okay
9 months ago
so this? and this:
9 months ago
looks fine at first glance
9 months ago
let's see your urls.py file as well
9 months ago
```from django.contrib import admin
from django.urls import path, include, repath from wagtail.admin import urls as wagtailadminurls
from wagtail import urls as wagtailurls from wagtail.documents import urls as wagtaildocsurls
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(wagtailadminurls)), path("documents/", include(wagtaildocsurls)),
path(r'comments/', include('djangocommentsxtd.urls')),
path("", include(wagtailurls)), ] + static(settings.MEDIAURL,
documentroot=settings.MEDIAROOT)```
9 months ago
please enclose that in a code block
9 months ago
`from django.contrib import admin
from django.urls import path, include, repath from wagtail.admin import urls as wagtailadminurls
from wagtail import urls as wagtailurls from wagtail.documents import urls as wagtaildocsurls
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(wagtailadminurls)), path("documents/", include(wagtaildocsurls)),
path(r'comments/', include('djangocommentsxtd.urls')),
path("", include(wagtailurls)), ] + static(settings.MEDIAURL, documentroot=settings.MEDIAROOT)`
9 months ago
edit the message please
9 months ago
code block please
9 months ago
my bad
9 months ago
looks fine to me
9 months 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
9 months ago
similarly this is what my files look like in admin on django/wagtail
9 months ago
what are their status codes?
9 months ago
you mean when i clik? pae not found
9 months ago
status code please
9 months ago
im sorry i don't know how tofind that
9 months ago
can you direct me please?
9 months ago
sorry but that's outside of the realm of what we can help with
9 months ago
okay
9 months ago
I'm just going to assume it's 404, meaning you need to fix your urls.py file
9 months ago
ok
9 months ago
is there an example online of what the setup should look like? i think it would help me, i couldn't find one
9 months ago
you've asked at a very bad time, the repo I would have sent has gone missing
9 months ago
thats what i thought
9 months ago
does this provide any info?
https://web-production-2206.up.railway.app/media/images/bamiesmainphoto_toijouv.original.jpg
This is the URL that is given to the photoo when i upload it
9 months ago
I'm on mobile, so no
9 months ago
what's your current volume mount
9 months ago
/app/media
9 months ago
what's your media settings
9 months ago
```MEDIAROOT = os.getenv("RAILWAYVOLUMEMOUNTPATH", os.path.join(BASE_DIR, "media"))
MEDIA_URL = "/media/"```
9 months ago
ive been trying different iterations of it
9 months ago
again, use the code you originally posted
9 months 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?
9 months ago
what makes you say it's sent to the wrong location, does the volume's metrics increase?
9 months ago
no nothing
9 months ago
yes actaully
9 months ago
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
9 months ago
also, changed it to the original code from the post and printed the MEDIA_ROOT and it gave '/media' is this right?
9 months ago
do you not have BASE_DIR defined?
9 months ago
BASE_DIR = Path(__file__).resolve().parent.parent
9 months ago
why is that not printing anything?
9 months 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?
9 months ago
it's complicated, it's best if you upload the media again
9 months ago
okay
9 months ago
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"
9 months ago
as mentioned, your urls.py is wrong
9 months ago
you need something to actually serve the media files on that url path
9 months ago
how can i do this? is there any more documentation on it
9 months ago
so this is wrong?
9 months ago
you said it looked fine here
9 months ago
I'm not a Django developer
9 months ago
this wouldn't be specific to railway
9 months ago
but usually, for example if i was using google buckets, there would be information on how to serve it
9 months ago
right but you are serving from disk, so it's not platform specific
9 months 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?
9 months 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
9 months ago
is it better to not use railway volumes?
9 months ago
there's nothing wrong with using railway volume's, I strongly advise you not to ask AI about railway
9 months 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?
9 months 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
9 months ago
sorry i thought it was related to railway volumes. typically i would be able to find the answer in the documentation
9 months ago
apologies
9 months ago
the mount point stuff was in the docs, but this has now become purely coding questions about django
9 months ago
and for coding questions related to Django, railway's docs aren't going to help