์ ์ (STATIC_ROOT) ํ์ผ์ ์ถ์ํ ๊ทธ๋ฆผ์ผ๋ก ํ์ํ๋ ๋ฐฉ๋ฒ์ ์ฐพ์ ์ ์์ต๋๋ค. ์ธ๋ถ(http://....) ๋ฐ ๋ฏธ๋์ด(MEDIA_ROOT) ํ์ผ์์๋ง ์๋ํ๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ด๊ฒ์ ์ ์ ์ด๋ฏธ์ง์ ์ถ๋ ฅ ํฌ๊ธฐ๊ฐ ํญ์ ๊ฐ์ง ์์ ๋(์ฌ์ฉ์ ํ๊ฒฝ ์ค์ , ํ ๋ง ๋ฑ์ ํตํด) ๋งค์ฐ ์ ์ฉํฉ๋๋ค.
STATIC_ROOT๋ฅผ ์ฌ์ฉํ๋ ์ผ๋ถ ์ ์ฅ์๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด 'django.core.files.storage.FileSystemStorage'๋ฅผ ์ฌ์ฉํ๊ณ location=settings.STATIC_ROOT ๋ฐ base_url=settings.STATIC_URL๋ก ์ธ์คํด์คํํ ์ ์์ต๋๋ค. ์ด๊ฒ์ ์คํ์ค๋ฒํ๋ก์์ ๊ณ์ ์งํํ์ญ์์ค. ๋ฒ๋ .
5๋
์ด ์ง๋ ํ์๋ https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/base.py#L100 ๋๋ฌธ์ DEFAULT ์ ์ฅ์๋ฅผ ๋ณ๊ฒฝํ์ง ์๊ณ ์ ์ ํ์ผ์์ ์ธ์ ์์ฑํ ๊ฐ๋ฅ์ฑ์ด ์์ต๋๋ค.
StackOverflow๋ ๊ตฌํ์ผ๋ก ์ธํด ๋์์ด ๋์ง ์์ต๋๋ค.
๊ทธ๊ฒ์ ๊ณ ์น ๊ธฐํ๊ฐ ์์ต๋๊น? get_thumbnail()
๋ฅผ ํตํด ์ฌ์ฉ์ ์ง์ ์คํ ๋ฆฌ์ง ์ธ์คํด์ค๋ฅผ ์ ๋ฌํ๋ฉด ์ถฉ๋ถํฉ๋๋ค.
๋ค์์ ํจ์น์ ์์ ๋๋ค. https://github.com/marcinn/sorl-thumbnail/commit/61557b41169f0656063c557735ef62908a5fcaab
ํธ์ง : ์ฃ์กํฉ๋๋ค. thumbnail.url
์ ์ถ๋ ฅ์ด ์ ํจํ ๊ฒ ๊ฐ์ง๋ง cached.url
์์ ๊ฒ์ํ ๋ /static/
/media/
์ ๋์ฌ๊ฐ ๋ถ์ต๋๋ค. ๋ด๋ถ์ ๋ ๋ถ์์ง ๊ฒ์ด ์์ต๋๋ค.
EDIT (2) : ์คํ ๋ฆฌ์ง ์ฝ๋๋ฅผ ์ญ์ง๋ ฌํํ๋ ๋ฐ ์ค๊ณ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์คํ ๋ฆฌ์ง ํด๋์ค๊ฐ ๋ก๋๋๊ณ ๊ธฐ์กด ์ธ์คํด์ค๋ฅผ ์ฌ์ฉํ๋ ๋์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ธ์คํด์คํ๋ฉ๋๋ค. ์ฆ, sorl.thumbnail์ ์คํ ๋ฆฌ์ง ์ธ์คํด์ค๋ฅผ ์ฌ์ฌ์ฉํ์ง ์๊ณ ๊ณ ์ ํ ์ธ์คํด์ค๋ฅผ ์์ฑํฉ๋๋ค(๋ค๋ฅด๊ฒ ๊ตฌ์ฑ๋จ). ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก FileSystemStorage์์ ์์ํ๊ณ ์ฌ์ฉ์ ์ง์ ์ด๋์ ๋ผ์ด์ ๋ฅผ ์ ์ํ ์ ์์ต๋๋ค.
๊ทธ๊ฒ์ ์ ์ฉํ ํ์๋ ๋๊ตฌ๋ ์ฝ๊ฒ ๋ฌด์์ด๋ ์ธ๋ค์ผ์ ์์ฑํ ์ ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ ์ฌ์ฉ์ ์ ์ ํ
ํ๋ฆฟ ํ๊ทธ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
from django.core.files.storage import FileSystemStorage
from django.conf import settings
from django import template
from sorl.thumbnail.templatetags.thumbnail import ThumbnailNode
register = template.Library()
class StaticThumbnailStorage(FileSystemStorage):
def __init__(self, *args, **kw):
super(StaticThumbnailStorage, self).__init__(
*args, location='/path/to/custom/static/'
base_url=settings.STATIC_URL, **kw)
storage = StaticThumbnaikStorage()
class StaticThumbnailNode(ThumbnailNode):
def _get_thumbnail(self, file_, geometry, **options):
options['storage'] = storage
return super(StaticThumbnailNode, self)._get_thumbnail(
file_, geometry, **options)
@register.tag
def static_thumbnail(parser, token):
return StaticThumbnailNode(parser, token)
์ค์ ์ ๋ณ๊ฒฝํ ํ์๊ฐ ์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค์์ ํจ์น์ ์์ ๋๋ค. https://github.com/marcinn/sorl-thumbnail/commit/61557b41169f0656063c557735ef62908a5fcaab
ํธ์ง : ์ฃ์กํฉ๋๋ค.
thumbnail.url
์ ์ถ๋ ฅ์ด ์ ํจํ ๊ฒ ๊ฐ์ง๋งcached.url
์์ ๊ฒ์ํ ๋/static/
/media/
์ ๋์ฌ๊ฐ ๋ถ์ต๋๋ค. ๋ด๋ถ์ ๋ ๋ถ์์ง ๊ฒ์ด ์์ต๋๋ค.EDIT (2) : ์คํ ๋ฆฌ์ง ์ฝ๋๋ฅผ ์ญ์ง๋ ฌํํ๋ ๋ฐ ์ค๊ณ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ์คํ ๋ฆฌ์ง ํด๋์ค๊ฐ ๋ก๋๋๊ณ ๊ธฐ์กด ์ธ์คํด์ค๋ฅผ ์ฌ์ฉํ๋ ๋์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ธ์คํด์คํ๋ฉ๋๋ค. ์ฆ, sorl.thumbnail์ ์คํ ๋ฆฌ์ง ์ธ์คํด์ค๋ฅผ ์ฌ์ฌ์ฉํ์ง ์๊ณ ๊ณ ์ ํ ์ธ์คํด์ค๋ฅผ ์์ฑํฉ๋๋ค(๋ค๋ฅด๊ฒ ๊ตฌ์ฑ๋จ). ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก FileSystemStorage์์ ์์ํ๊ณ ์ฌ์ฉ์ ์ง์ ์ด๋์ ๋ผ์ด์ ๋ฅผ ์ ์ํ ์ ์์ต๋๋ค.
๊ทธ๊ฒ์ ์ ์ฉํ ํ์๋ ๋๊ตฌ๋ ์ฝ๊ฒ ๋ฌด์์ด๋ ์ธ๋ค์ผ์ ์์ฑํ ์ ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ ์ฌ์ฉ์ ์ ์ ํ ํ๋ฆฟ ํ๊ทธ๋ฅผ ์์ฑํ ์ ์์ต๋๋ค.
์ค์ ์ ๋ณ๊ฒฝํ ํ์๊ฐ ์์ต๋๋ค.