River Tam
River Tam

Reputation: 3216

Displaying image held in ImageField in a django template

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?

Upvotes: 0

Views: 757

Answers (1)

Raunak Agarwal
Raunak Agarwal

Reputation: 7228

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/'

Upvotes: 0

Related Questions