From 2f0ec1a1cdcba4b22c48dd952b774220772e43e5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 4 Jan 2025 16:46:21 -0800 Subject: [PATCH] web_framework: Disable caching templates files in development mode - When a template page is updated, we are having to restart service in order for the new changes to reflect. This is due to caching of template files starting Django 4.1[1]. Disable this behavior in development mode to allow reload the browser page to see changes reflected. Links: https://docs.djangoproject.com/en/5.0/releases/4.1/#templates Tests: - Change a template file and reload the page without restarting service. The changes should reflect immediately. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- plinth/web_framework.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plinth/web_framework.py b/plinth/web_framework.py index 691b0228a..6ca815061 100644 --- a/plinth/web_framework.py +++ b/plinth/web_framework.py @@ -45,6 +45,14 @@ def init(): settings.STATIC_URL = '/'.join([cfg.server_dir, 'static/']).replace('//', '/') settings.USE_X_FORWARDED_HOST = cfg.use_x_forwarded_host + if cfg.develop: + # Disable template caching in development so that page updates don't + # require service restart. + del settings.TEMPLATES[0]['APP_DIRS'] + settings.TEMPLATES[0]['OPTIONS']['loaders'] = [ + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + ] kwargs = {} for setting in dir(settings):