pythondjangohttp-status-code-404django-settingsdjango-media

Page not found 404 Django media files


I am able to upload the files to media folder /peaceroot/www/media/ that I have set up in settings.py as below

MEDIA_ROOT = '/peaceroot/www/media/'
MEDIA_URL = '/media/'

But through admin I tried to access the uploaded image file, and got a 404 error:

http://localhost:8000/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg

It exists at peaceroot/www/media/items/1a39246c-4160-4cb2-a842-12a1ffd72b3b.jpg.


Solution

  • Add media url entry in your project (not app) urlpatterns:

    from django.conf.urls.static import static
    from django.conf import settings
    
    ...
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)