0

I'm trying to display an ImageField image in my django template.

I'm doing it as such:

<img src="{{ pic.content.url }}" />

This, however, shows an image for mysite.com/appname/appname/picturename.ext. (which I'm like 90% sure is wrong; I don't know what's right, though. The images are kept in the larger django-site folder, and I don't know if apache can serve them directly by url)

My site settings.py file has the media directory correct (it uploads using the admin page and all that jazz), but this merely isn't working.

How do I show the image?

River Tam
  • 3,096
  • 4
  • 31
  • 51

1 Answers1

0

I am assuming you have done the required MEDIA settings. Make sure you are passing the RequestContext from your view and try changing your src to

<img src="{{MEDIA_URL}}{{pic.content.url}}" />

Update:

I think you need to change your media settings:

MEDIA_ROOT = '/var/www/mysite/media/' #This needs to point to the media folder MEDIA_URL = '/media/'

Raunak Agarwal
  • 7,117
  • 6
  • 38
  • 62
  • I've tried that as well. I'm pretty sure that's then it doubles up and gives me an image with the source website.com/appname/appname/picturename.ext. My current structure is as follows: website media appname appname models.py, templates, etc. The media url points to the 'media' folder there, and it's saving in media/appname. However, the url is taking it as a relative address. In other words, it's not looking at media/appname, it's looking at appname/appname, because it thinks it's starting in appname, not starting in media. – River Tam Dec 01 '12 at 14:36
  • It might be better if I knew exactly what I should be doing with the MEDIA_ROOT and MEDIA_URL. As it is, I have the MEDIA_ROOT = '/var/www/mysite/' and the MEDIA_URL = 'media/' – River Tam Dec 01 '12 at 14:45