Page not found 404 Django media files

madhu131313 picture madhu131313 · Mar 29, 2016 · Viewed 26.3k times · Source

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

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

then I am getting 404 error.

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

Answer

v1k45 picture v1k45 · Mar 29, 2016

Add media url entry in your project urlpatterns:

from django.conf.urls.static import static
from django.conf import settings

...
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)