์ด ๋งํฌ๋ก ๋ค์ด๊ฐ์ media๋ถ๋ถ ๋ฐ๋ผํ๊ธฐ๐ media ๋ฐ๋ก๊ฐ๊ธฐ
โmodels.py๋ ์ด๋ ๊ฒ ์ค์ ํ๋๋ก ํ๋ค
class Pictures(models.Model):
text = models.TextField()
image= models.ImageField(upload_to="blogimg")
๐ํฐ๋ฏธ๋์ ์์ฑ
โ
pip install pillow
pip install django-imagekit
๐setting.py์ ์๋ INSTALLED_APPS ์์ ์์ฑ
โ
INSTALLED_APPS = [
'imagekit',
]
๐models.py ์์
โ
from django.db import models
from imagekit.models import ImageSpecField #์ธ๋ค์ผ ์ง์
from imagekit.processors import ResizeToFill #์ธ๋ค์ผ ํฌ๊ธฐ
class Pictures(models.Model):
text = models.TextField()
image= models.ImageField(upload_to="blogimg")
image_thumbnail = ImageSpecField(source='image', processors=[ResizeToFill(120,60)]) #(๊ฐ๋ก,์ธ๋ก)
๐settings.py์ ์๋ INSTALLED_APPS ๊ดํธ ์์ ์์ฑ
โ
{% for blog in blog.all %}
<img src="{{blog.image.url}}" width="500">
<br>
{{blog.text}}
<br><br>
<img src="{{blog.image_thumbnail.url}}">
{% endfor %}