我有一个插件,我试图在从文件夹加载模板之前加载一个 my_assets python 包。
我收到的错误是:CRITICAL: No assets environment configured in Jinja2 environment
def foo(generator):
self._templates = {}
self._templates_path = []
self._templates_path.append(os.path.expanduser(os.path.join(self.theme, 'templates')))
self._templates_path += self.settings['EXTRA_TEMPLATES_PATHS']
theme_path = os.path.dirname(os.path.abspath(__file__))
simple_loader = FileSystemLoader(os.path.join(theme_path, "themes", "simple", "templates"))
self.env = Environment(
trim_blocks=True,
lstrip_blocks=True,
loader=ChoiceLoader([
PackageLoader('my_assets', 'templates'),
FileSystemLoader(self._templates_path),
simple_loader,
PrefixLoader({'!simple': simple_loader})
]),
extensions=self.settings['JINJA_EXTENSIONS'],
)
self.env.filters.update({'strftime': DateFormatter()})
custom_filters = self.settings['JINJA_FILTERS']
self.env.filters.update(custom_filters)
def register():
signals.generator_init.connect(foo)