试图在Pelican插件中覆盖jinja ChoiceReloader

时间:2015-05-07 18:37:04

标签: python jinja2 pelican

我有一个插件,我试图在从文件夹加载模板之前加载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)

1 个答案:

答案 0 :(得分:0)

发现这实际上是由于我的插件与使用A B white 0 yellow 0 yellow 1 green 0 white 1 yellow 2 的鹈鹕资产插件冲突造成的。只需覆盖self.env

刚刚结束使用

self.env.loader