开发者

Why is my Django app not displaying dynamic images when the path is correct?

开发者 https://www.devze.com 2022-12-10 20:27 出处:网络
My Django 1.1 app uses dynamic images. I\'m confused about why the path generated from my template tag:

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 genera开发者_如何学JAVAted from MEDIA_ROOT is correct on my computer and it works fine.

Why would the image not display correctly?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号