简体   繁体   English

加载和重用Django模板过滤器

[英]Load and Reuse Django Template Filters

Is it possible to load a django template tag/filter to use as a function in one of my template tags? 是否可以加载Django模板标签/过滤器以用作我的模板标签之一的功能?

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. 我正在尝试加载一些django.contrib.humanize过滤器,以便可以将其应用于某些自定义模板标签的结果。 I can't seem to import them at all, and I don't want to have to rewrite any of that code. 我似乎根本无法导入它们,而且我也不必重写任何代码。

Template tags are just Python functions; 模板标签只是Python函数; 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. django.contrib.humanize.templatetags.humanize模块具有单独的功能来完成工作,因此在这种特定情况下甚至更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM