0

I'm a newbie to django. I'm developing a project in django 1.3. Problem is I'm uploading a image from the admin panel

class About(models.Model):

    image = models.ImageField(upload_to='about')
    files = models.FileField(upload_to='about')

Here is my template tag

<img class="profile_pic" src="{{ about.image }}" />

My setting file is as below

MEDIA_ROOT = path("media/")
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
STATICFILES_DIRS = (
    path('static/'),
)

I checked that image is uploaded to /media/about/image_name. Problem is it rendered in the template as "/about/imagename" but not shoing. When I manually go to that image url it showing a 404 error.

themunna
  • 47
  • 1
  • 6

2 Answers2

3

<img class="profile_pic" src="{{ about.image.url }}" />

UPDATE

Also in your urls.py:

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^' + settings.MEDIA_URL.lstrip('/'), 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT})
zsquare
  • 9,916
  • 6
  • 53
  • 87
  • nope! not working. But the image is now showing the path which should be ok. Should I use any url rule for media folder? – themunna Jul 23 '11 at 12:53
0

It worked!... After importing setting.MEDIA_ROOT in the urls.py file then I added a media rule so ITs working now..

BTW It also need

{{ about.image.url }} 

as @zsquare(thanks) said earlier Here is the media rule

(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}),
themunna
  • 47
  • 1
  • 6