我正在为我的Django网站尝试Jinja2。
I am trying Jinja2 for my Django website.
现在,由于Jinja2不是官方的Django模板引擎,并且拒绝识别/加载我使用的模板标签
Now, since Jinja2 is not official Django templating engine and its refusing to recognise / load the template tags I was using prior to Jjinja2.
现在,即使必须在模板标签创建方面进行更改,那么如何在第三方应用程序中进行反映呢?
Now, even if there has to be a change in the template tags creation, then how is it possible to reflect across the 3rd party apps?
在那种情况下,由于系统必须按照Jinja2运行,因此似乎无法使用Jinja2。
In that case it seems impossible to use Jinja2 since the system has to work as per Jinja2.
(我是还使用棺材作为Jinja-Django的适配器)。
(I am also using coffin as an adapter for Jinja-Django).
推荐答案根据 coffin docs ,您将必须将所有自定义django模板标签重写为自定义Jinja2扩展名。
According to coffin docs you will have to rewrite any custom django templates tags as custom Jinja2 extensions.
您还可以使用jinja2宏功能来模拟Django的模板标签。最明显的区别是对于Jinja2宏,有必要通过模板上下文提供所有上下文数据,而在Django标签中,您可以使用其他方式(例如从数据库加载或调用其他Python库)访问数据。
You could also use jinja2 macros feature to emulate the Django's template tags. The most notable difference is that for Jinja2 macros it will be necessary to provide all the context data via the template context, while in Django tags you can access data using other ways (like loading from the database or calling other Python libraries).
我已经使用Jinja2模板已有一段时间了,并且从未需要创建自定义模板标签。
I've been using Jinja2 templates for a while and never had a need to create a custom template tag.
可以在网站上的一个应用程序中使用django模板,而在另一应用程序中使用jinja2,这不是问题,但是从django模板导入或扩展jinja2模板并不容易,反之亦然。
It is possible to use django templates in one app on the site and jinja2 in another app, it is not a problem, but it is not readily possible to import or extend jinja2 templates from django templates and vs versa.
更多推荐
如何在Jinja 2中使用3rd party应用模板标签?
发布评论