缩小尺寸的图像在大图像工作时未显示 [英] reduced size image not shown while big image works
问题描述
这是我的这个问题的完整代码。
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)
#任何手动设置到这里
self.object.moderator = self.request.user
self.object.image = extract(self.object.url)
self.object.save()
return HttpResponseRedirect(reverse('post',args = [self.object.slug]))
提取方法
def extract(url):
g = Goose()
article = g.extract(url = url)
resposne = {'image':article.top_image.src}
return article.top_image.src
我的模型,保存图片(已被提取)
class Post(models。模型):
image = models.ImageField(upload_to =images,blank = True,null = True)
image_thumbnail = ImageSpecField(source ='image',
processors = [ResizeToFill 70,70)],
format ='PNG',
options = {'quality':60}
)
对于post.html
< img src ={{post .image_thumbnail}}alt =/>
< img src ={{post.image}}alt =/>
第二个img正在工作,而第一个显示小盒子显示破损的图像
我有正确安装枕头,并且
根据我在讨论聊天中的讨论,缩略图的图像url是: p>
< img src =CACHE / IMAGE / http:/imgur.com/lalala/path/to/image.png> ;
这是错误的。
你需要修复url,也可能将图像文件转到ImageSpecField,以便正确缩略图。
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
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..
这篇关于缩小尺寸的图像在大图像工作时未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!