我是新的,不知道CSS。我在我的Django站点上使用了一个模板。
当我直接在html页面上添加图像链接时,它们会自动调整到图片网格中。
然而,当我添加代码和上传图片从网站,他们都显示不同的大小。
我想他们都一致和适合预先确定的盒子大小。
<div class="container-fixed">
<div class="adoption1">
<h1 class="wow fadeIn animated">Meet our Penguins</h1>
<div class="grid-cats wow">
{% for post in posts %}
<div class="col-md-4 thumbs">
<a href="">
<figure class="effect-marley">
<img src="{{ post.image2.url }}" alt=""/>
<figcaption>
<h2>SUPER<span>CUTE</span></h2>
<p>{{ post.content }}</p>
</figcaption>
</figure>
</a>
</div>
{% endfor %}
###如果你想调整图像大小,覆盖你的模型保存方法
from PIL import Image
def save(self,*args,**kwargs):
super().save(*args,**kwargs)
img = Image.open(self.image2.path)
if img.height>your_max_height or img.width>your_max_width:
out_size =(your_desired_height ,your_desired_width)
img.resize(out_size)
img.save(self.image2.path)