From e4e87221ffbef4d6956a100964f7e70fde5a853d Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Fri, 30 Apr 2021 18:09:38 +0200 Subject: [PATCH] Create state.template on access --- panel/io/state.py | 13 ++++++------- panel/viewable.py | 10 +++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/panel/io/state.py b/panel/io/state.py index 115824af1f..1c6de21276 100644 --- a/panel/io/state.py +++ b/panel/io/state.py @@ -351,14 +351,13 @@ def session_args(self): @property def template(self): + from ..config import config if self.curdoc in self._templates: - return self._templates[self.curdoc] - - @template.setter - def template(self, template): - if self.curdoc is None: - raise ValueError("Can not set template when state.curdoc is None.") - self._templates[self.curdoc] = template + template = self._templates[self.curdoc] + else: + template = config.template(theme=config.theme) + self._templates[self.curdoc] = template + return template @property def user(self): diff --git a/panel/viewable.py b/panel/viewable.py index 3fbe9fca73..5a24268cf6 100644 --- a/panel/viewable.py +++ b/panel/viewable.py @@ -316,13 +316,9 @@ def servable(self, title=None, location=True, area='main'): if isinstance(handler, logging.StreamHandler): handler.setLevel(logging.WARN) if config.template: - if state.template: - template = state.template - if template.title == template.param.title.default and title: - template.title = title - else: - params = {'title': title} if title else {} - state.template = template = config.template(theme=config.theme, **params) + template = state.template + if template.title == template.param.title.default and title: + template.title = title if area == 'main': template.main.append(self) elif area == 'sidebar':