Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top