Skip to content

Commit 1dd3f4b

Browse files
committed
Implement static file serving with whitenoise
1 parent bd0afec commit 1dd3f4b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ venv/
3030
ENV/
3131
env.bak/
3232
venv.bak/
33+
app/static_files/

app/app/settings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"django.contrib.contenttypes",
3737
"django.contrib.sessions",
3838
"django.contrib.messages",
39+
"whitenoise.runserver_nostatic",
3940
"django.contrib.staticfiles",
4041
"users",
4142
"general",
@@ -49,6 +50,7 @@
4950

5051
MIDDLEWARE = [
5152
"django.middleware.security.SecurityMiddleware",
53+
"whitenoise.middleware.WhiteNoiseMiddleware",
5254
"django.contrib.sessions.middleware.SessionMiddleware",
5355
"django.middleware.common.CommonMiddleware",
5456
"django.middleware.csrf.CsrfViewMiddleware",
@@ -126,11 +128,21 @@
126128
# Static files (CSS, JavaScript, Images)
127129
# https://docs.djangoproject.com/en/5.0/howto/static-files/
128130

129-
STATIC_URL = "static/"
131+
STATIC_URL = "/static/"
130132
STATICFILES_DIRS = [
131133
BASE_DIR / "static",
132134
]
133135

136+
STATIC_ROOT = BASE_DIR / "static_files"
137+
STORAGES = {
138+
"default": {
139+
"BACKEND": "django.core.files.storage.FileSystemStorage",
140+
},
141+
"staticfiles": {
142+
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
143+
},
144+
}
145+
134146
# Default primary key field type
135147
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
136148

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
django==5.0.2
22
psycopg2-binary
33
gunicorn
4+
whitenoise

0 commit comments

Comments
 (0)