Django의 운영환경에서는 WebServer에서 접근할 Static files(CSS, JavaScript, Images)을 한 곳에 모아서 관리해야한다.

 

1. Static files(CSS, JavaScript, Images) 위치 설정은 환경파일(Settings.py)에 한다.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # manage.py 파일이 있는 Directory Path

# Web URL of Static files's Directory
STATIC_URL = "/static/"

# Directory Path of Static files
STATIC_ROOT = BASE_DIR + "_static"

# collectstatic 실행 시 수집할 Static file들이 저장된 Directory들을 배열로 지정한다. 
# 여기에 지정된 모든 경로의 파일들이 STATIC_ROOT에 정의된 디렉토리로 복사된다.
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]

 

2. Static files 수집명령

(.venv) python manage.py collectstatic # 옵션 [--settings=...]