Skip to content

Commit

Permalink
Use whitenoise to serve static files
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Dec 29, 2024
1 parent 242c251 commit 9615773
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies = [
"sentry-sdk>=2.19.2",
"setuptools>=75.6.0", # Needed by django-bootstrap-form
"typenv>=0.2.0",
"whitenoise>=6.8.2",
]

[project.optional-dependencies]
Expand Down
14 changes: 14 additions & 0 deletions src/comics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"django.contrib.messages",
"django.contrib.sessions",
"django.contrib.sites",
"whitenoise.runserver_nostatic", # Before staticfiles
"django.contrib.staticfiles",
]
LOCAL_APPS = [
Expand All @@ -128,6 +129,7 @@
#
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.middleware.http.ConditionalGetMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down Expand Up @@ -266,6 +268,15 @@
TIME_FORMAT = "H:i"


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


# Static files (CSS, JavaScript, etc.)
#
# Path on disk to where static files will be collected to and served from.
Expand Down Expand Up @@ -293,6 +304,9 @@

# Static files - django-compressor
#
# Compress files offline to enable WhiteNoise to serve the generated files.
COMPRESS_OFFLINE = True
#
# Explicitly use HtmlParser to avoid depending on BeautifulSoup through the use
# of LxmlParser
COMPRESS_PARSER = "compressor.parser.HtmlParser"
Expand Down
3 changes: 0 additions & 3 deletions src/comics/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@
pass
else:
urlpatterns += debug_toolbar_urls()


urlpatterns += static(settings.STATIC_URL)
11 changes: 11 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9615773

Please sign in to comment.