在Javascript中使用Jinja2模板的最佳方法?

时间:2021-11-20 00:01:17

I'm trying to AJAXify some functionality of a page that uses Jinja2 and Flask. Problem is that I want the entire Jinja2 template to be rendered by Javascript but, this isn't possible with some of the available libraries as they don't support all the features of jinja2. What's the best way to solve this issue?

我正在尝试AJAXify使用Jinja2和Flask的页面的一些功能。问题是我想通过Javascript渲染整个Jinja2模板,但是这对于一些可用的库是不可能的,因为它们不支持jinja2的所有功能。解决这个问题的最佳方法是什么?

2 个解决方案

#1


0  

There seems to be https://github.com/syrusakbary/jsjinja library now:

现在似乎有https://github.com/syrusakbary/jsjinja库:

JsJinja lets you use your Jinja2 templates in Javascript. It compile the Jinja2 templates to Javascript with no restrictions.

JsJinja允许您在Javascript中使用Jinja2模板。它将Jinja2模板编译为Javascript,没有任何限制。

Not tried it though.

虽然没试过。

#2


0  

I've solved this same problem by writing Jasinja. It supports a fairly large subset of the Jinja template syntax.

我写了Jasinja,解决了同样的问题。它支持Jinja模板语法的相当大的子集。

#1


0  

There seems to be https://github.com/syrusakbary/jsjinja library now:

现在似乎有https://github.com/syrusakbary/jsjinja库:

JsJinja lets you use your Jinja2 templates in Javascript. It compile the Jinja2 templates to Javascript with no restrictions.

JsJinja允许您在Javascript中使用Jinja2模板。它将Jinja2模板编译为Javascript,没有任何限制。

Not tried it though.

虽然没试过。

#2


0  

I've solved this same problem by writing Jasinja. It supports a fairly large subset of the Jinja template syntax.

我写了Jasinja,解决了同样的问题。它支持Jinja模板语法的相当大的子集。