본문 바로가기
장고

[ Django ] 기타 설정

by 자동매매 2023. 5. 3.

Then we need to update our static settings so it will be used in production. In your text editor open settings.py. Add whitenoise to the INSTALLED_APPS above the builtin staticfiles app and also to MIDDLEWARE on the third line. Order matters for both INSTALLED_APPS and MIDDLEWARE.

At the bottom of the file add new lines for both STATIC_ROOT and STATICFILES_STORAGE.

It should look like the following.

Code

# blog_project/settings.py INSTALLED_APPS = [

'blog.apps.BlogConfig',

'accounts.apps.AccountsConfig',

'django.contrib.admin',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'whitenoise.runserver_nostatic', # new!

'django.contrib.staticfiles',

]

MIDDLEWARE = [

'django.middleware.security.SecurityMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'whitenoise.middleware.WhiteNoiseMiddleware', # new!

'django.middleware.common.CommonMiddleware',

'django.middleware.csrf.CsrfViewMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.contrib.messages.middleware.MessageMiddleware',

'django.middleware.clickjacking.XFrameOptionsMiddleware',

]

...

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') # new!

STATIC_URL = '/static/'

STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

'장고' 카테고리의 다른 글

[ Django ] 내장 인증  (0) 2023.05.03
[ Django ] django Views  (0) 2023.05.02
[ Django ] Index  (0) 2023.05.02
App생성  (0) 2023.04.12

댓글