Add whitenoise for static files

This commit is contained in:
Jake Howard 2022-06-09 09:03:00 +01:00
parent 531b75c128
commit e0b95fd269
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 9 additions and 7 deletions

2
.gitignore vendored
View file

@ -302,3 +302,5 @@ cython_debug/
#.idea/
# End of https://www.toptal.com/developers/gitignore/api/python,node
/collected-static

View file

@ -1,3 +1,4 @@
Django==4.0.5
wagtail==3.0
django-environ==0.8.1
whitenoise[brotli]==6.2.0

View file

@ -41,17 +41,19 @@ INSTALLED_APPS = [
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
]
MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
]
@ -108,10 +110,7 @@ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
# ManifestStaticFilesStorage is recommended in production, to prevent outdated
# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).
# See https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#manifeststaticfilesstorage
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATIC_ROOT = os.path.join(BASE_DIR, "collected-static")
STATIC_URL = "/static/"