image.url empty in template when defining values('image') in view
I'm building a Django based web application, which has a Post model with images. These models are working fine in my template:
{% if gallery_list %}
<div id="gallery">
{% for gallery_item in gallery_list %}
<div class="gallery_item">
{% if gallery_item.image %}
<div class="image">
<a href="#"><img src="{{ gallery_item.image.url }}" /></a>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% else %}
<p>No images are available.</p>
{% endif %}
I have a working index page which displays all my images in my template just fine when calling:
gallery_list = Post.objects.all().order_by('-id')
But if I call:
gallery_list = Post.objects.all().order_by('-id').values('image')
You get nothing in the gallery_item.image.url field. However, the gallery_list.image field has the image object in it. (the div.image is created).
Do I need additional information in the values() call to get the url template function to work?
I'm building a Django based web application, which has a Post model with images. These models are working fine in my template:
{% if gallery_list %}
<div id="gallery">
{% for gallery_item in gallery_list %}
<div class="gallery_item">
{% if gallery_item.image %}
<div class="image">
<a href="#"><img src="{{ gallery_item.image.url }}" /></a>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% else %}
<p>No images are available.</p>
{% endif %}
I have a working index page which displays all my images in my template just fine when calling:
gallery_list = Post.objects.all().order_by('-id')
But if I call:
gallery_list = Post.objects.all().order_by('-id').values('image')
You get nothing in the gallery_item.image.url field. However, the gallery_list.image field has the image object in it. (the div.image is created).
Do I need additional information in the values() call to get the url template function to work?
No comments:
Post a Comment