a year ago
I have a django app deployed with a Volume mounted on /app/media. When I put hacky code to list the media directory, I can see that the files are there. I can also see that I can upload to the directory via the Django admin.
However, when I access these files via the browser in their django paths, I get 404. Not Found.
Here is my urls.py
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path
from django.urls.conf import include
from .views import (contact_success_view, contact_view, game_detail, home,
service_detail)
urlpatterns = [
path('admin/', admin.site.urls),
path('', home, name='home'),
path('game/<slug:slug>/', game_detail, name='game_detail'),
path('service/<slug:slug>/', service_detail, name='service_detail'),
path('ckeditor5/', include('django_ckeditor_5.urls')),
path('contact/', contact_view, name='contact'),
path('success/', contact_success_view, name='success'),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)And I have in my settings.py:
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
11 Replies
a year ago
Hello,
Can you try the syntax shown here -
https://github.com/railwayapp-templates/django-volume/blob/main/mysite/urls.py#L25
brody
Hello,Can you try the syntax shown here -https://github.com/railwayapp-templates/django-volume/blob/main/mysite/urls.py#L25
a year ago
That worked! I have been stuck at this all day, thanks a ton!
Status changed to Solved brody • about 1 year ago
9 months ago
God. I've been stuck in this problem for two days. Thank u guys!
Status changed to Awaiting Railway Response Railway • 10 months ago
9 months ago
Now i have annoter question. Are my uploaded files going to my volume service in this case?
romeuriffatti
Now i have annoter question. Are my uploaded files going to my volume service in this case?
9 months ago
If you have a volume attached, and your application is saving the uploaded files to the volume, Yes.
Status changed to Awaiting User Response Railway • 10 months ago
9 months ago
How do i config to my images stay persistant and dont lost them every time a make a commit on github. Sorry for english mistakes, im not native
Status changed to Awaiting Railway Response Railway • 10 months ago
9 months ago
image = models.ImageField(upload_to='', null=True) if this is my uploadto from my model
And
MEDIA_ROOT = BASE_DIR / 'media' MEDIA_URL = 'media/'this is how i config my settings
Are my files going to the volume or do i need to do something else?
brody
Hello,Can you try the syntax shown here -https://github.com/railwayapp-templates/django-volume/blob/main/mysite/urls.py#L25
9 months ago
Have you tried what I have suggested to the owner of this thread?
Status changed to Awaiting User Response Railway • 10 months ago
9 months ago
yes, but thats not how it works. I now resolved the problem. The question is that u can't use the same volume of the database to the application media. I created another one and then it worked.
Status changed to Awaiting Railway Response Railway • 10 months ago
9 months ago
Yep, media is not stored in the database, it is stored in the filesystem, glad you where able to figure it out!
Status changed to Awaiting User Response Railway • 10 months ago
Status changed to Solved brody • 10 months ago