diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index 694eca6a18..fd66ee7719 100644 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -1582,10 +1582,42 @@ Default: ``True`` Controls whether unhandled exceptions should generate a generic 500 response or present the user with a pretty-formatted debug information page. +When set, CACHED_TEMPLATE_LOADERS will not be cached. + This setting should **always** be set to ``False`` for production deployments as the debug page can display sensitive information to users and attackers alike. +``TEMPLATE_LOADERS`` +--------------------------- + +.. versionadded:: 10.0.0(Newton) + +These template loaders will be the first loaders and get loaded before the +CACHED_TEMPLATE_LOADERS. Use ADD_TEMPLATE_LOADERS if you want to add loaders at +the end and not cache loaded templates. +After the whole settings process has gone through, TEMPLATE_LOADERS will be: + + TEMPLATE_LOADERS += ( + ('django.template.loaders.cached.Loader', CACHED_TEMPLATE_LOADERS), + ) + tuple(ADD_TEMPLATE_LOADERS) + +``CACHED_TEMPLATE_LOADERS`` +--------------------------- + +.. versionadded:: 10.0.0(Newton) + +Template loaders defined here will have their output cached if DEBUG +is set to False. + +``ADD_TEMPLATE_LOADERS`` +--------------------------- + +.. versionadded:: 10.0.0(Newton) + +Template loaders defined here will be be loaded at the end of TEMPLATE_LOADERS, +after the CACHED_TEMPLATE_LOADERS and will never have a cached output. + ``SECRET_KEY`` -------------- diff --git a/openstack_dashboard/settings.py b/openstack_dashboard/settings.py index 82960120e4..951733a848 100644 --- a/openstack_dashboard/settings.py +++ b/openstack_dashboard/settings.py @@ -123,6 +123,15 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'openstack_dashboard.context_processors.openstack', ) +TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader',) + +CACHED_TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', + 'horizon.loaders.TemplateLoader',) + +ADD_TEMPLATE_LOADERS = [] + TEMPLATE_DIRS = ( os.path.join(ROOT_PATH, 'templates'), ) @@ -283,15 +292,12 @@ try: except ImportError: logging.warning("No local_settings file found.") -_LOADERS = ('django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', - 'horizon.loaders.TemplateLoader',) - if DEBUG: - TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader',) + _LOADERS + TEMPLATE_LOADERS += CACHED_TEMPLATE_LOADERS + tuple(ADD_TEMPLATE_LOADERS) else: - TEMPLATE_LOADERS = ('horizon.themes.ThemeTemplateLoader', - ('django.template.loaders.cached.Loader', _LOADERS),) + TEMPLATE_LOADERS += ( + ('django.template.loaders.cached.Loader', CACHED_TEMPLATE_LOADERS), + ) + tuple(ADD_TEMPLATE_LOADERS) # allow to drop settings snippets into a local_settings_dir LOCAL_SETTINGS_DIR_PATH = os.path.join(ROOT_PATH, "local", "local_settings.d") diff --git a/releasenotes/notes/bug-1568764-cached-template-loaders-3536f35e11099eba.yaml b/releasenotes/notes/bug-1568764-cached-template-loaders-3536f35e11099eba.yaml new file mode 100644 index 0000000000..62bb525635 --- /dev/null +++ b/releasenotes/notes/bug-1568764-cached-template-loaders-3536f35e11099eba.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - The final django TEMPLATE_LOADERS configuration will now be generated from + TEMPLATE_LOADERS, CACHED_TEMPLATE_LOADERS and ADD_TEMPLATE_LOADERS + settings. See the settings documentation for more information.