장고

[ Django ] 기타 설정

자동매매 2023. 5. 3. 03:49

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'