django - sorl-thumbnail: Creating a thumbnail inside a for loop in a template -


i trying create thumbnail size of 100x100 px image. using loop, , loops works , image rendered reason when trying create thumbnail doesn't work.

here code:

{% post_images in post.sellpostimage_set.all %}            <img class="thumbnail" src="{{ post_images.pictures.url }}" />              {% thumbnail post_images "100x100" crop="center" im %}                 <img src="{{ im.pictures.url }}" width="{{ im.width }}" height="{{ im.height }}">             {% endthumbnail %}  {% endfor %} 

views.py

def post(request, post_name_slug):     context_dict = {}     try:          post = sellpost.objects.get(slug=post_name_slug)         context_dict['post'] = post          poster_posts = sellpost.objects.filter(user=post.user).order_by('-timestamp')         context_dict['poster_posts'] = poster_posts          post_image = sellpostimage.objects.filter(post=poster_posts)         context_dict['post_image'] = post_image          poster = post.user         context_dict['poster'] = poster      except sellpost.doesnotexist:         return redirect('index')     return render(request, 'post.html', context_dict, ) 

edit: if use in thumbnail src {{ im.url }} can image location weird.. http://127.0.0.1:8000/media/cache/9b/0b/9b0b04d65b1075ed4c3e7783131caef6.jpg , again thumbnail image still not being rendered. shows url broken, , when try go image location url 404 error.

it looks plural in wrong spot:

{% post_images in post.sellpostimage_set.all %} 

should be:

{% post_image in post.sellpostimage_set.all %} 

post_image = sellpostimage.objects.filter(post=poster_posts) context_dict['post_image'] = post_image 

should be:

post_images = sellpostimage.objects.filter(post=poster_posts) context_dict['post_images'] = post_images 

or:

post_image = sellpostimage.objects.get(post=poster_posts) context_dict['post_image'] = post_image 

why do in template:

{% post_images in post.sellpostimage_set.all %} 

if have post_images in context?


how work?

<img class="thumbnail" src="{{ post_images.pictures.url }}" /> 

shouldn't be:

<img class="thumbnail" src="{{ post_image.picture.url }}" /> 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -