Skip to content

Commit

Permalink
Use whitenoise to help Django better serve static files, even during
Browse files Browse the repository at this point in the history
development (without needing NGINX for that).
See https://whitenoise.readthedocs.io/en/latest
  • Loading branch information
bdklahn committed Sep 8, 2023
1 parent 32fafe3 commit 101ceff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ json5
matplotlib
pandas
plotly
whitenoise
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ tenacity==8.2.3
# via plotly
tzdata==2023.3
# via pandas
whitenoise==6.5.0
# via -r requirements.in
8 changes: 8 additions & 0 deletions webdesign/webdesign/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"whitenoise.runserver_nostatic",
"django.contrib.staticfiles",
"polls",
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
Expand Down Expand Up @@ -124,6 +126,12 @@
os.path.join(BASE_DIR, 'static'),
)

STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = os.path.join("/", BASE_PATH, "media/")

Expand Down

0 comments on commit 101ceff

Please sign in to comment.