如何在Django模板变量上应用多个过滤器? [英] How to apply multiple filters on a Django template variable?

查看:47
本文介绍了如何在Django模板变量上应用多个过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说这可行:

{{game.description |安全}}

{{ game.description|safe }}

但这失败了:

{{ game.description|safe|slice:"65" }}

是否可以在Django模板中的变量上应用两个或多个过滤器?

Is there a way to apply two or more filters on a variable in Django templates?

推荐答案

虽然OP发布问题已经很久了,但是对于其他可能需要此信息的人来说,这似乎对我来说很有效:

Although it's quite past when the OP posted the question, but for other people that may need the info, this seems to work well for me:

您可以重写

{{ game.description|safe|slice:"65" }}

{% with description=game.description|safe %}
{{description|slice:"65"}}
{% endwith %}

这篇关于如何在Django模板变量上应用多个过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆