Jinja2 compile extension after includes

后端 未结 1 1317
感情败类
感情败类 2021-01-06 20:45

In Jinja2, is it possible to have a Node from the AST render after all include statements have completed?

This is a key piece of a solution

相关标签:
1条回答
  • 2021-01-06 21:26

    Jinja2 does streaming of template data. The template is evaluated instruction for instruction into a stream of smaller strings that gets concatenated into an actual unicode string by the render() method. However you can also get hold of the stream by calling into generate() instead of render().

    With some in-band signalling and postprocessing of the stream one might probably be able to implement something like that, but it's against the way of how Jinja2 was designed so it might break horribly and is totally unsupported.

    0 讨论(0)
提交回复
热议问题