开发者

Is it possible to use a django filter on the result of a templatetag?

I have a template tag which returns d开发者_运维知识库atetime objects converted to the user's timezone. To format it, I'd prefer the builtin filter "date" to format it.

Is it possible to use a filter on the result of a template tag?


You can wrap your custom templatetag with 'filter' templatetag:

{% filter date %}
    {% your_custom_tag %}
{% endfilter %}

More information here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#filter


Yes, if course you can. Filters are just functions that can be imported. Import the filter function you need from django.template.defaultfilters and pass your arguments to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜