From 5ce645cac68c37c076d6a0c3a5fd3aad39834b7e Mon Sep 17 00:00:00 2001 From: IYStoychev21 Date: Tue, 23 Jan 2024 18:33:17 +0200 Subject: [PATCH] Add whitenoise module --- backend/requirements.txt | 1 + backend/valium_backend/settings.py | 17 ++++++++++++++--- backend/valium_backend/urls.py | 4 +--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/requirements.txt b/backend/requirements.txt index 00177e0..864b10a 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -51,3 +51,4 @@ uritemplate==4.1.1 urllib3==2.1.0 vine==5.1.0 wcwidth==0.2.13 +whitenoise==6.6.0 diff --git a/backend/valium_backend/settings.py b/backend/valium_backend/settings.py index 868e19f..6b791a7 100644 --- a/backend/valium_backend/settings.py +++ b/backend/valium_backend/settings.py @@ -33,6 +33,7 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', + 'whitenoise.runserver_nostatic', 'django.contrib.staticfiles', 'allauth.account', 'allauth', @@ -49,8 +50,9 @@ ] MIDDLEWARE = [ - 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'corsheaders.middleware.CorsMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -200,6 +202,15 @@ ACCOUNT_DEFAULT_HTTP_PROTOCOL = "https" SESSION_COOKIE_DOMAIN = ".valiumonline.live" CSRF_COOKIE_DOMAIN = ".valiumonline.live" -DEBUG = False + DEBUG = False + +STATIC_ROOT = BASE_DIR / "staticfiles" + +STORAGES = { + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + } +} -STATIC_ROOT = BASE_DIR / "static" +STATIC_HOST = os.environ.get("VITE_BASE_URL_BACKEND") +STATIC_URL = str(STATIC_HOST) + "/static/" diff --git a/backend/valium_backend/urls.py b/backend/valium_backend/urls.py index 5ed7279..e3ccbe3 100644 --- a/backend/valium_backend/urls.py +++ b/backend/valium_backend/urls.py @@ -18,8 +18,6 @@ from rest_framework import permissions from drf_yasg.views import get_schema_view from drf_yasg import openapi -from django.conf.urls.static import static -from django.conf import settings schema_view = get_schema_view( openapi.Info( @@ -39,4 +37,4 @@ path('api/v1/inbox/', include('inbox.urls')), path('api/v1/wills/', include('wills.urls')), path('docs/', schema_view.with_ui('swagger', cache_timeout=0)), -] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) +]