Skip to content

Commit fba2788

Browse files
committed
Enable whitenoise to serve project staticfiles
1 parent f0d6e02 commit fba2788

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

fly.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ console_command = '/code/manage.py shell'
1212
CSRF_TRUSTED_ORIGINS = 'https://thebook.lhc.net.br,https://thebook.fly.dev'
1313
DEBUG = '0'
1414
PORT = '8000'
15-
STORAGES = '{"default": {"BACKEND": "storages.backends.s3.S3Storage", "OPTIONS": {"bucket_name": "lhc-bookkeeping"}}, "staticfiles": {"BACKEND": "storages.backends.s3.S3Storage", "OPTIONS": {"bucket_name": "lhc-thebook-static"}}}'
16-
STATIC_URL = 'https://lhc-thebook-static.s3.us-east-005.backblazeb2.com/'
15+
STORAGES = '{"default": {"BACKEND": "storages.backends.s3.S3Storage", "OPTIONS": {"bucket_name": "lhc-bookkeeping"}}, "staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"}}'
1716
AWS_REQUEST_CHECKSUM_CALCULATION = 'WHEN_REQUIRED'
1817
AWS_RESPONSE_CHECKSUM_VALIDATION = 'WHEN_REQUIRED'
1918
OTEL_EXPORTER_OTLP_PROTOCOL = 'http/protobuf'

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ opentelemetry-exporter-otlp = "^1.36.0"
2525
opentelemetry-distro = "^0.58b0"
2626
opentelemetry-instrumentation-django = "^0.58b0"
2727
python-dateutil = "^2.9.0.post0"
28+
whitenoise = "^6.11.0"
2829

2930
[tool.poetry.group.dev.dependencies]
3031
pytest = "^8.3.3"
@@ -49,7 +50,7 @@ build-backend = "poetry.core.masonry.api"
4950
collectstatic = "python manage.py collectstatic"
5051
makemigrations = "python manage.py makemigrations"
5152
migrate = "python manage.py migrate"
52-
run = "OTEL_PYTHON_DJANGO_INSTRUMENT=False python manage.py runserver"
53+
run = "OTEL_PYTHON_DJANGO_INSTRUMENT=False python manage.py runserver --nostatic"
5354
shell = "python manage.py shell"
5455
test = "pytest -s --cov=thebook"
5556

thebook/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
MIDDLEWARE = [
8787
"debug_toolbar.middleware.DebugToolbarMiddleware",
8888
"django.middleware.security.SecurityMiddleware",
89+
"whitenoise.middleware.WhiteNoiseMiddleware",
8990
"django.contrib.sessions.middleware.SessionMiddleware",
9091
"django.middleware.common.CommonMiddleware",
9192
"django.middleware.csrf.CsrfViewMiddleware",
@@ -187,6 +188,7 @@
187188
# Static files (CSS, JavaScript, Images)
188189
# https://docs.djangoproject.com/en/5.1/howto/static-files/
189190

191+
STATIC_ROOT = BASE_DIR / "staticfiles"
190192
STATIC_URL = config("STATIC_URL", default="static/")
191193

192194
# Default primary key field type
@@ -203,7 +205,7 @@
203205

204206
STORAGES = config(
205207
"STORAGES",
206-
default='{"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}, "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"}}',
208+
default='{"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"}, "staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"}}',
207209
cast=lambda x: json.loads(x),
208210
)
209211

0 commit comments

Comments
 (0)