From 1ffdb5d2ba85859f769a9406d08d79ff7dc88843 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Sat, 21 Mar 2026 22:49:18 +1100 Subject: [PATCH] Fix static resources issue --- Dockerfile | 1 + core/settings.py | 16 +--------------- k8s/manifest.yaml | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d8d33b..9ffbc46 100644 --- a/Dockerfile +++ b/Dockerfile @@ -136,6 +136,7 @@ COPY --chown=appuser:appuser links/ ./links/ COPY --chown=appuser:appuser netscan/ ./netscan/ COPY --chown=appuser:appuser new_theme/ ./new_theme/ COPY --chown=appuser:appuser templates/ ./templates/ +COPY --chown=appuser:appuser static/ ./static/ COPY --chown=appuser:appuser qdrant_sync.py ./ # Final cleanup diff --git a/core/settings.py b/core/settings.py index 19e6ec9..4a8a838 100644 --- a/core/settings.py +++ b/core/settings.py @@ -25,21 +25,6 @@ INSTALLED_APPS = [ ROOT_URLCONF = 'core.urls' -# Why WhiteNoise failed: WhiteNoiseMiddleware was at the bottom of MIDDLEWARE (position 8). WhiteNoise requires being right after SecurityMiddleware (position 2) so -# it can intercept /static/* requests before other middleware processes them. When it was last, the requests were falling through to Django URL routing, which -# returned HTML 404 pages. -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'core.middleware.CustomLocaleMiddleware', # 替换原来的 LocaleMiddleware - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -177,6 +162,7 @@ LOCALE_INDEPENDENT_PATHS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'core.middleware.CustomLocaleMiddleware', # 使用自定义中间件 'django.middleware.common.CommonMiddleware', diff --git a/k8s/manifest.yaml b/k8s/manifest.yaml index 4ecfa6d..fd07ee2 100644 --- a/k8s/manifest.yaml +++ b/k8s/manifest.yaml @@ -103,7 +103,7 @@ spec: initContainers: - name: links-init image: "ghcr.io/wahyd4/links:main" - command: ["sh", "-c", "uv run manage.py migrate && uv run manage.py collectstatic --noinput && uv run manage.py rebuild_search_index"] + command: ["sh", "-c", "uv run manage.py migrate && uv run manage.py rebuild_search_index"] volumeMounts: - name: data mountPath: /app/data