neridaj
neridaj

Reputation: 2183

Django - Serving files from media directory

I've deployed a new website to my staging and production servers but for some reason the images in the media directory are displaying 404 errors. The path to the image is correct and the image is located at that path:

<img src="/media/projects/hair/2012/test-1/13221803.jpg" alt="Slide 1" width="570" height="270" style="">

ls -la ~/.virtualenvs/website/project/media/projects/hair/2012/test-1
total 144
drwxr-x--- 2 username username   4096 Aug 27 16:43 .
drwxr-x--- 3 username username   4096 Aug 27 16:43 ..
-rwxrwxr-x 1 username username 131719 Aug 27 16:43 13221803.jpg

settings.py:

MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
MEDIA_URL = '/media/'

Am I having problems because the image file is nested within other directories? Files are being served from the static directory just fine, any ideas?

Thanks,

Jason

Upvotes: 2

Views: 2662

Answers (1)

karthikr
karthikr

Reputation: 99620

Does your urls.py have this target?

    urlpatterns += patterns('',
            (r'^media/(?P<path>.*)$', 'django.views.static.serve', {
                    'document_root': settings.MEDIA_ROOT}))

Upvotes: 4

Related Questions