feat: add django-whitenoise
This commit is contained in:
@@ -41,6 +41,7 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"whitenoise.middleware.WhiteNoiseMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
@@ -122,3 +123,26 @@ USE_TZ = True
|
||||
# them, so the prefix must be added manually for the admin assets to load under
|
||||
# the /scores sub-path.
|
||||
STATIC_URL = f"{FORCE_SCRIPT_NAME.rstrip('/')}/static/"
|
||||
STATIC_ROOT = BASE_DIR / "staticfiles"
|
||||
|
||||
# WhiteNoise serves static files directly from the app (no separate web server
|
||||
# needed), with compression and far-future cache headers. In production the
|
||||
# manifest backend hashes filenames for cache-busting (requires collectstatic);
|
||||
# locally we skip the manifest and serve straight from the finders so no
|
||||
# collectstatic step is needed.
|
||||
STORAGES = {
|
||||
"default": {
|
||||
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
||||
},
|
||||
"staticfiles": {
|
||||
"BACKEND": (
|
||||
"whitenoise.storage.CompressedStaticFilesStorage"
|
||||
if DEBUG
|
||||
else "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
# Serve static files from the app dirs in development (we run under daphne, which
|
||||
# does not auto-serve static like runserver does).
|
||||
WHITENOISE_USE_FINDERS = DEBUG
|
||||
|
||||
Reference in New Issue
Block a user