๊ทธ๋์ Debug = False๋ก ๊ฐ๋ฐ ์ค์ธ django-compressor๋ฅผ ์ป์์ต๋๋ค. ๊ทธ๋ฌ๋ Debug = True๋ก ์ค์ ํ๋ฉด django-compressor๊ฐ ์ฌ๋ฐ๋ฅธ URL, ํ์ผ ๋ฐ ๋ชจ๋ ๊ฒ์ ์์ฑํ๋ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง Django ์์ฒด๋ ํด๋น ํ์ผ์ ๋ํด 404๋ฅผ ๋ฐํํฉ๋๋ค.
๋๋ ๊ฐ์ง๊ณ ์๋ค
STATIC_ROOT = os.path.join(PROJECT_DIR, "static_media")
๊ทธ๋ฆฌ๊ณ ๋ด ํ๋ก์ ํธ์ static_media ํด๋ ์์๋ ์์ถ๊ธฐ์ ์ํด ์์ฑ๋ CACHE/css/bfdeac875f7a.css ํ์ผ์ด ์ค์ ๋ก ๋ณด์ ๋๋ค.
์์ฑ๋ HTML ํ์ผ ๋ด๋ถ์์๋ ๋ณผ ์ ์์ต๋๋ค.
<link rel="stylesheet" href="/static/CACHE/css/bfdeac875f7a.css" type="text/css" />
๊ทธ๋ฌ๋ ํ์ด์ง๊ฐ ๋ก๋๋ ๋ runserver๋ ๋ค์๊ณผ ๊ฐ์ด ๋งํฉ๋๋ค.
[21/Dec/2012 22:28:44] "GET /static/CACHE/css/bfdeac875f7a.css HTTP/1.1" 404 276
๋ด๊ฐ ๋ญ๊ฐ๋ฅผ ๋์น๊ณ ์์ต๋๊น? ๋๋ ์ด๋ฏธ
'django.core.context_processors.static',
์ TEMPLATE_CONTEXT_PROCESSORS
'compressor.finders.CompressorFinder',
์ STATICFILES_FINDERS
'compressor',
์ INSTALLED_APPS
๊ฐ์ฌ ํด์!
์๋ ํ์ธ์,
๊ทํ๋ฅผ ๋๊ธฐ ์ํด ๊ทํ์ ์ค์ ์ ๋ํ ์ ๋ณด๊ฐ ์กฐ๊ธ ๋ ํ์ํฉ๋๋ค.
๊ฐ์ฌ ํด์
์๋ ํ์ธ์,
๋ค์ ์ค์ ์ผ๋ก Django 1.4.3์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
...
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(PROJECT_DIR, "static_media")
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_DIR, "static"),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
'compressor.finders.CompressorFinder',
)
COMPRESS_PRECOMPILERS = (
('text/coffeescript', 'coffee --compile --stdio'),
('text/x-scss', 'sass --scss {infile} {outfile}'),
)
...
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
...
'compressor',
...
)
...
static_media
์์ ์๋์ผ๋ก ๋ฃ์ ํ์ผ์ /static/
url์์๋ ์ก์ธ์คํ ์ ์์ผ๋ฏ๋ก staticfile์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ตฌ์ฑํ์ง ์์์ ๊ฒ์
๋๋ค. ์ค์ํ๋ค๋ฉด Django 1.3์์๋ ๋ง์ด๊ทธ๋ ์ด์
ํ์ต๋๋ค. ๋ด๊ฐ ๋ฌด์์ ์๋ํด์ผํ๋์ง ์๊ฐ์ด ์์ผ์ญ๋๊น?
๋ํ runserver๋ Debug๊ฐ true์ผ ๋ ๋ด static_media
ํด๋์ ํ์ผ์ ์ฑ๊ณต์ ์ผ๋ก ๊ฐ์ ธ์ค์ง๋ง false์ผ ๋ ์คํจํฉ๋๋ค...
์ฃ์กํฉ๋๋ค. ๋ด๊ฐ ๋ ์ผ์ฐ ๋์ณค๋ค๋ ๊ฒ์ด ๋ฏฟ๊ธฐ์ง ์์ต๋๋ค. DEBUG๊ฐ _True_์ผ ๋ ๋ฌธ์ ๊ฐ ์๋ค๋ ๊ฒ์ ์ด๋ป๊ฒ๋ ์ฝ์์ต๋๋ค.
์ด์จ๋ . DEBUG = False์ธ ๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก runserver๋ ์ฑ๋ฅ ๋ฐ ๋ณด์ ๋ฌธ์ ๋ก ์ธํด ์ ์ ํ์ผ ์์ฒด๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ๊ฑฐ๋ถํฉ๋๋ค. ์ด๊ฒ์ ํ๋ก๋์ ์์ ์ด๊ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค. DEBUG๊ฐ False์ผ ๋ ๋ก์ปฌ์์ ์ ์ ํ์ผ์ ์ ์ ํ๊ฒ ํ ์คํธํ๋ ค๋ฉด https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/์ ์ค๋ช ๋ ๊ฒ์ฒ๋ผ --insecure ํ๋๊ทธ๋ฅผ runserver์ ์ ๋ฌํด์ผ ํฉ๋๋ค.
๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๊น?
์ค ์ด๋ฐ, ๋ด ๋์. ์๋ ์ง๋ฌธ์์ ์ค์๋ก "True"์ "False"๋ฅผ ๋ฐ๊ฟจ์ต๋๋ค. ํผ๋์ ๋๋ ค ์ฃ์กํฉ๋๋ค!
๊ทธ๋ฆฌ๊ณ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค. ๊ทธ๋ฌ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค!
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ฃ์กํฉ๋๋ค. ๋ด๊ฐ ๋ ์ผ์ฐ ๋์ณค๋ค๋ ๊ฒ์ด ๋ฏฟ๊ธฐ์ง ์์ต๋๋ค. DEBUG๊ฐ _True_์ผ ๋ ๋ฌธ์ ๊ฐ ์๋ค๋ ๊ฒ์ ์ด๋ป๊ฒ๋ ์ฝ์์ต๋๋ค.
์ด์จ๋ . DEBUG = False์ธ ๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก runserver๋ ์ฑ๋ฅ ๋ฐ ๋ณด์ ๋ฌธ์ ๋ก ์ธํด ์ ์ ํ์ผ ์์ฒด๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ ๊ฑฐ๋ถํฉ๋๋ค. ์ด๊ฒ์ ํ๋ก๋์ ์์ ์ด๊ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํ ๊ฒ์ ๋๋ค. DEBUG๊ฐ False์ผ ๋ ๋ก์ปฌ์์ ์ ์ ํ์ผ์ ์ ์ ํ๊ฒ ํ ์คํธํ๋ ค๋ฉด https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/์ ์ค๋ช ๋ ๊ฒ์ฒ๋ผ --insecure ํ๋๊ทธ๋ฅผ runserver์ ์ ๋ฌํด์ผ ํฉ๋๋ค.
๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๊น?