fix: 修复图片显示问题,添加whitenoise优化静态文件性能
Some checks failed
Deploy to Server / deploy (push) Has been cancelled

This commit is contained in:
爽哒哒
2026-03-21 12:18:51 +08:00
parent 68ebf7f100
commit 555b5badbf
6 changed files with 29 additions and 32 deletions

View File

@@ -58,6 +58,7 @@ INSTALLED_APPS = [
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@@ -173,6 +174,15 @@ STATICFILES_DIRS = [
BASE_DIR / 'static',
]
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
# 媒体文件配置
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'