๐Ÿ’ธ Django ํŠœํ† ๋ฆฌ์–ผ: ๋ฌด๋ฃŒ ๋ฐฐํฌ ์‹œ ๋ฏธ๋””์–ด ํŒŒ์ผ ์„ค์ •

7255 ๋‹จ์–ด djangodevopspythontutorial

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ ...



๋ฐฐํฌ(๋ฐ ํ”„๋กœ๋•์…˜ ๐Ÿค) ๋™์•ˆ ๋ฌด๋ฃŒ๋กœ ๋ฏธ๋””์–ด ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šฐ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

ํ๋ฆผ



์ด๋ฅผ ์œ„ํ•ด cloudinary ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. settings ํŒŒ์ผ์—์„œ ๋ช‡ ๊ฐ€์ง€๋งŒ ์ˆ˜์ •ํ•˜๋ฉด Django์—์„œ ๋ฏธ๋””์–ด(์—…๋กœ๋“œ๋œ ํŒŒ์ผ)๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ •์  ํŒŒ์ผ๊ณผ ๋ฏธ๋””์–ด ํŒŒ์ผ์˜ ์ฐจ์ด์ 



์›น ๊ฐœ๋ฐœ์—์„œ ์ •์  ํŒŒ์ผ์€ "์ •์ "์ƒํƒœ๋ฅผ ์œ ์ง€ํ•˜๋Š” ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์ดํŠธ์™€ ์ƒํ˜ธ ์ž‘์šฉํ•˜๋Š” ์ˆœ๊ฐ„์—๋„ ํ•ด๋‹น ํŒŒ์ผ์ด ์ˆ˜์ •๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ธฐ๋ณธ ์„ธ ๊ฐ€์ง€ ์ •์  ํŒŒ์ผ์€ ํ…œํ”Œ๋ฆฟ์—์„œ ์ œ๊ณต๋˜๋Š” CSS , Javascript ๋ฐ images ์ž…๋‹ˆ๋‹ค.

Django ์•ฑ ๋ฐฐํฌ์—์„œ๋Š” ์ •์  ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด whitenoise์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Django ์ž์ฒด๋Š” ๊ฐœ๋ฐœ ์ค‘์— ์ •์  ํŒŒ์ผ์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์—(์„ฑ๋Šฅ ๋ฌธ์ œ ๋•Œ๋ฌธ์—).

heroku์— Django ์•ฑ์„ ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ๋ณธ ํŠœํ† ๋ฆฌ์–ผ์„ ๋ณด๋ ค๋ฉด ์ด ํŠœํ† ๋ฆฌ์–ผ์„ ๋ณด์‹ญ์‹œ์˜ค.




๋ฏธ๋””์–ด ํŒŒ์ผ



๋ฐ˜๋ฉด ๋ฏธ๋””์–ด ํŒŒ์ผ์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‚ฌ์šฉ์ž๊ฐ€ ์—…๋กœ๋“œํ•œ ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์ง€์†์ ์œผ๋กœ ๋ณ€๊ฒฝ๋˜๋Š” ํŒŒ์ผ์ด๋ฏ€๋กœ ์ œ๊ณต๋˜๋Š” ์ž์ฒด ๋ฐฉ์‹์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ํด๋ผ์šฐ๋“œ ์Šคํ† ๋ฆฌ์ง€



Cloudinary Storage API๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋ฌด๋ฃŒ ๊ณ„์ •์„ ์ƒ์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. here.



๊ณ„์ • ๋งŒ๋“ค๊ธฐ๋ฅผ ๋ˆ„๋ฅด๊ณ  ์ด๋ฉ”์ผ๋กœ ๊ณ„์ •์„ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.

์ž๊ฒฉ ์ฆ๋ช…์ด ํฌํ•จ๋œ ๋Œ€์‹œ๋ณด๋“œ๋ฅผ ๋ฐ›๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ๋‚˜์ค‘์— ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค ๐Ÿ˜‰.

์„ค์ • ์ˆ˜์ •:



์šฐ์„  ๋ฏธ๋””์–ด ๊ด€๋ฆฌ์ž๋กœ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ํด๋ผ์šฐ๋“œ ํŒจํ‚ค์ง€๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ ๋ช‡ ๊ฐ€์ง€ ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•ด ๋ด…์‹œ๋‹ค.

pip install cloudinary django-cloudinary-storage


์ด์ œ ๋ช‡ ๊ฐ€์ง€ ๋ชจ๋“ˆ์„ ๊ฐ€์ ธ์˜ค๊ฒ ์Šต๋‹ˆ๋‹ค.

# At the top of the settings
import cloudinary
import cloudinary_storage


๊ทธ๋ฆฌ๊ณ  ์„ค์น˜๋œ ์•ฑ ์ˆ˜์ •

INSTALLED_APPS = [
    # Other apps ...

    # Media Cloudinary
    'cloudinary',
    'cloudinary_storage',
]



๋งˆ์ง€๋ง‰์œผ๋กœ ์ด ์ฃผ์„ ๋’ค์— ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค.

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/



# Cloudinary stuff
CLOUDINARY_STORAGE = {
    'CLOUD_NAME': <your cloud name>,
    'API_KEY': <your api key>,
    'API_SECRET': <your secret api>,
}

DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'


๊ทธ๋Ÿฌ๋‚˜ ๋ˆ„๊ตฐ๊ฐ€๋Š” ์ €์—๊ฒŒ ์ด๋ ‡๊ฒŒ ๋งํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋‹ค๋‹ˆ์—˜, ๋ฏธ์ณค์–ด?

๊ทธ๋ฆฌ๊ณ  ๋„ค, ๋งž์Šต๋‹ˆ๋‹ค!

๋”ฐ๋ผ์„œ ์•„์ด๋””์–ด๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž๊ฒฉ ์ฆ๋ช…์„ ๋ณดํ˜ธํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ๋ชจ๋“  ํ‚ค๋ฅผ ์„œ๋ฒ„์— ๋„ฃ๊ณ  ์†Œ์Šค ํŒŒ์ผ์ด ์•„๋‹Œ ์ฝ”๋“œ๋ฅผ ๋ฐฐํฌํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.
settings.py ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋‚ด ์•ฑ์„ keroku์— ๋ฐฐํฌํ•  ๊ฒƒ์ด๋ฏ€๋กœ Python Decouple ์„ ์‚ฌ์šฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

heroku์—์„œ Python decouple์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค๋ฉด .

์ด ๊ฒฝ์šฐ Cloudinary ์„ค์ •์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

from decouple import config

CLOUDINARY_STORAGE = {
    'CLOUD_NAME': config('CLOUD_NAME', default=""),
    'API_KEY': config('API_KEY', default=""),
    'API_SECRET': config('API_SECRET', default=""),
}

DEFAULT_FILE_STORAGE = 'cloudinary_storage.storage.MediaCloudinaryStorage'


์˜์‹ฌ์ด๋‚˜ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๊นŒ? ์˜๊ฒฌ์— ์•Œ๋ ค์ฃผ์‹ญ์‹œ์˜ค.

์‹œ๊ฐ„ ๋‚ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์ด ์œ ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค ๐Ÿค—.

Follow me in My blog,
to get more awesome tutorials like this one.
Please consider supporting me on Ko-fi you help me a lot to
continue building this tutorials!.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ