views:

70

answers:

2

My Django 1.1 app uses dynamic images. I'm confused about why the path generated from my template tag: {{image_product.photo.path}}

looks correct, but does not display the requested image.

This generates a path that works:

src='/media/{{image_product.photo}}'   => <img src='/media/lcdtvs/product1.jpg'>

This DOES NOT work:

src='{{image_product.photo.path}}'     => <img src='/Users/Bryan/work/review_app/media/lcdtvs/product1.jpg'>

I checked to confirm that the Absolute path generated from MEDIA_ROOT is correct on my computer and it works fine.

Why would the image not display correctly?

+1  A: 

Not familiar with Django, but I'd guess you need to have file:///Users/... in the second snippet.

Benjamin Oakes
+2  A: 

Two things to keep in mind:

  1. What you want is the {{image_field.url}} method (not the path).

  2. If it still is 404, either you need to setup your server correctly, or if you are using the development server you need to enable it to server static files.

Arthur Debert
I fixed it, you were correct, but I think there was a typo. It should say {{image_field.photo.url}}
BryanWheelock