Written by
django-style
on
on
Django web develpment Whitenoise 사용하는 방법
Django web develpment Whitenoise 사용하는 방법
Django로 개발한 웹 사이트를 헤로쿠 서버에 Deploy하게 되면
static 파일들을 가져오지 못하는 경우가 발생한다.
서버가 작동할 때 staticfiles에서 collectstatics 명령을
수행하게 되는데 이 과정이 정상작동이 안되는 것이다.
실제로 헤로쿠 서버에 배포를 하게 되면,
css, imgage, javascript 파일들이 정상 작동하지
않고 서버에서 404 response를 하고 있는 것을
확인할 수 있다.
이 문제를 해결하기 위한 방법이 whitenoise 패키지를
사용하는 것이다. Whitenoise는 static 파일들을
collecstatics 명령 수행 시 지정경로(static_root)에
파일들을 모아주는 역할을 담당한다.
# 1 설치 방법
pip install whitenoise
# 2 적용방법
your_project.settings.py에서 미들웨어로 향한다.
'django.middleware.security.SecurityMiddleware' , 'whitenoise.middleware.WhiteNoiseMiddleware' ,
여기서 주의해야 할 점은 반드시
Django Security Middleware 다음 줄에
whitenoise middleware를 추가해줘야
정상작동한다는 점이다.
from http://incomeplus.tistory.com/221 by ccl(A) rewrite - 2021-11-28 16:01:15