Make the collectstatic hack slightly better

This commit is contained in:
Andrew Godwin 2022-12-16 19:51:19 -07:00
parent 770f6728f6
commit 4a28e1708e
2 changed files with 11 additions and 2 deletions

View file

@ -1,3 +1,4 @@
import sys
from urllib.parse import urljoin
from django.conf import settings
@ -41,7 +42,15 @@ class StaticAbsoluteUrl(RelativeAbsoluteUrl):
"""
def __init__(self, path: str):
try:
static_url = staticfiles_storage.url(path)
except ValueError:
# Suppress static issues during the first collectstatic
# Yes, I know it's a big hack! Pull requests welcome :)
if "collectstatic" in sys.argv:
super().__init__("https://example.com/")
return
raise
if "://" in static_url:
super().__init__(static_url)
else:

View file

@ -32,7 +32,7 @@ COPY . /takahe
WORKDIR /takahe
RUN TAKAHE_DATABASE_SERVER="postgres://x@example.com/x" TAKAHE_DEBUG=true python3 manage.py collectstatic --noinput
RUN TAKAHE_DATABASE_SERVER="postgres://x@example.com/x" python3 manage.py collectstatic --noinput
EXPOSE 8000