问题
I really have no idea why it won't work, I did exactly same as other tutorials. Maybe the way I'm extracting image is the problem. I'm using imagekit and goose. Any help would be appreciated. Here is my Full Code for this problem .
class PostCreateView(CreateView):
model = Post
form_class = PostForm
template_name = 'main/add_post.html'
def form_valid(self, form):
self.object = form.save(commit=False)
# any manual settings go here
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)
self.object.save()
return HttpResponseRedirect(reverse('post', args=[self.object.slug]))
For extract method
def extract(url):
g = Goose()
article = g.extract(url=url)
resposne = {'image':article.top_image.src}
return article.top_image.src
my models, where image is saved(has been extracted)
class Post(models.Model):
image = models.ImageField(upload_to="images",blank=True, null=True)
image_thumbnail = ImageSpecField(source='image',
processors=[ResizeToFill(70,70)],
format='PNG',
options={'quality':60}
)
For post.html
<img src="{{ post.image_thumbnail }}" alt="" />
<img src="{{ post.image}}" alt="" />
second img is working, while the first one shows small box showing broken image I have installed pillow correctly, and
回答1:
according to discussion I had with you in discussion chat, the image url of thumbnail is:
<img src="CACHE/IMAGE/http:/imgur.com/lalala/path/to/image.png">
which is wrong.
you need to fix the url and possibly also hand image file over to ImageSpecField so it can thumbnail correctly..
来源:https://stackoverflow.com/questions/34551672/reduced-size-image-not-shown-while-big-image-works