加载和重用 Django 模板过滤器

发布于 2024-08-19 07:03:06 字数 142 浏览 5 评论 0原文

是否可以加载 django 模板标签/过滤器以用作我的模板标签之一中的函数?

我正在尝试加载一些 django.contrib. humanize 过滤器,以便我可以将它们应用到一些自定义模板标签的结果中。我似乎根本无法导入它们,而且我不想重写任何代码。

Is it possible to load a django template tag/filter to use as a function in one of my template tags?

I'm trying to load up some of the django.contrib.humanize filters so I can apply them to the results of some of my custom template tags. I can't seem to import them at all, and I don't want to have to rewrite any of that code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∝单色的世界 2024-08-26 07:03:06

模板标签只是 Python 函数;您可以导入它们的模块并不受惩罚地调用它们,唯一的要求是向它们传递适当的参数。 django.contrib. humanize.templatetags. humanize 模块具有单独的函数来完成这项工作,因此在特定情况下更容易。

Template tags are just Python functions; you can import their module and call them with impunity, the only requirement being that you pass them appropriate arguments. The django.contrib.humanize.templatetags.humanize module has separate functions to do the work, so it's even easier in that specific case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文