如何在Jinja 2中使用3rd party应用模板标签?

编程入门 行业动态 更新时间:2024-10-23 23:20:17
本文介绍了如何在Jinja 2中使用3rd party应用模板标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为我的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应用模板标签?

本文发布于:2023-11-26 17:49:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   标签   如何在   party   Jinja

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!