From b051ec72da823fa74efaa59e8d85949101c99023 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 11 Nov 2020 18:35:42 +0100 Subject: [PATCH] Add settings.SERVE_FILES and serve static files only for local development --- inventory_project/settings/base.py | 9 ++++++++- inventory_project/settings/local.py | 5 +++++ inventory_project/urls.py | 6 ++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/inventory_project/settings/base.py b/inventory_project/settings/base.py index ae6fc34..45a7786 100644 --- a/inventory_project/settings/base.py +++ b/inventory_project/settings/base.py @@ -7,11 +7,18 @@ from pathlib import Path as __Path from django.utils.translation import ugettext_lazy as _ - # Build paths inside the project: BASE_PATH = __Path(__file__).resolve().parent.parent.parent +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False + +# Serve static/media files by Django? +# In production Caddy should serve this! +SERVE_FILES = False + + # SECURITY WARNING: keep the secret key used in production secret! __SECRET_FILE = __Path(BASE_PATH, 'secret.txt').resolve() if not __SECRET_FILE.is_file(): diff --git a/inventory_project/settings/local.py b/inventory_project/settings/local.py index 055adcd..fe01672 100644 --- a/inventory_project/settings/local.py +++ b/inventory_project/settings/local.py @@ -15,6 +15,11 @@ from inventory_project.settings.base import * # noqa # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True + +# Serve static/media files for local development: +SERVE_FILES = True + + # Disable caches: CACHES = {'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}} diff --git a/inventory_project/urls.py b/inventory_project/urls.py index 006a18f..fe6e563 100644 --- a/inventory_project/urls.py +++ b/inventory_project/urls.py @@ -15,10 +15,12 @@ urlpatterns = [ # Don't use i18n_patterns() here path('ckeditor/', include('ckeditor_uploader.urls')), # TODO: check permissions? ] -if settings.DEBUG: + +if settings.SERVE_FILES: urlpatterns += static.static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static.static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) - import debug_toolbar +if settings.DEBUG: + import debug_toolbar urlpatterns = [url(r'^__debug__/', include(debug_toolbar.urls))] + urlpatterns