views:

183

answers:

1

Hello!

I am exploring file/images uploads in Django. I have a model with Photo class which has thumb ImageField. I uploaded thumb with admin panel and I made template which just gives <img src='{{photo.thumb.url}}' />. Unfortunately I don't get any images and when I try to get direct link it says "page not found". It seems that django either does not move them to media_url or maybe it has no permission to access it? I wonder what can I do to fix it.

Thanks a lot beforehand.

PS: Running django on dev server with sqlite db.

+1  A: 

The development server by default doesn't serve static files (see the documentation). You'll need to add the following code to the bottom of your urls.py to enable static file serving:

from django.conf import settings

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'%s(?P<path>.*)' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    )

That should sort you out.

elo80ka