Django

Django에서 WhiteNoise 사용하기

wangkisa 2019. 7. 11. 17:49

Django 에서 DEBUG = False 로 하게 되면

기존에 static 파일로 쓰던 것들이 모두 경로를 못찾게 된다.

 

그런때에 WhiteNoise 를 설치해 사용하면 해당 문제를 해결 할 수 있다.

 

WhiteNoise는 static파일들을 collectstatics 명령수행시 지정경로에 파일들을 모아주는 역할을 한다.


http://whitenoise.evans.io/en/stable/django.html

 

Using WhiteNoise with Django — WhiteNoise 4.1.2 documentation

This guide walks you through setting up a Django project with WhiteNoise. In most cases it shouldn’t take more than a couple of lines of configuration. I mention Heroku in a few places as that was the initial use case which prompted me to create WhiteNoise

whitenoise.evans.io

 

whitenoise 설치 방법

pip install whitenoise

 

settings.py 파일에서

 

미들웨어 부분 :

    'whitenoise.middleware.WhiteNoiseMiddleware',

 

static_root 부분 :

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'