self.root = os.path.abspath(root_directory)
self.templates = {}
- def load(self, name, parent_path=None):
+ def reset(self):
+ self.templates = {}
+
+ def resolve_path(self, name, parent_path=None):
if parent_path and not parent_path.startswith("<") and \
not parent_path.startswith("/") and \
not name.startswith("/"):
relative_path = os.path.abspath(os.path.join(file_dir, name))
if relative_path.startswith(self.root):
name = relative_path[len(self.root) + 1:]
+ return name
+
+ def load(self, name, parent_path=None):
+ name = self.resolve_path(name, parent_path=parent_path)
if name not in self.templates:
path = os.path.join(self.root, name)
f = open(path, "r")
if not getattr(RequestHandler, "_templates", None):
RequestHandler._templates = {}
if template_path not in RequestHandler._templates:
- RequestHandler._templates[template_path] = template.Loader(
- template_path)
+ loader = self.application.settings.get("template_loader") or\
+ template.Loader(template_path)
+ RequestHandler._templates[template_path] = loader
t = RequestHandler._templates[template_path].load(template_name)
args = dict(
handler=self,
# In debug mode, re-compile templates and reload static files on every
# request so you don't need to restart to see changes
if self.settings.get("debug"):
- RequestHandler._templates = None
+ if getattr(RequestHandler, "_templates", None):
+ map(lambda loader: loader.reset(),
+ RequestHandler._templates.values())
RequestHandler._static_hashes = {}
handler._execute(transforms, *args, **kwargs)