如何传递Django的urlize模板过滤器的autoescape参数? [英] How do I pass Django's urlize template filter its autoescape parameter?

查看:106
本文介绍了如何传递Django的urlize模板过滤器的autoescape参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Django urlize docs 说:

Django urlize docs say:


urlize 可选参数 autoescape 。如果 autoescape True ,链接文字和URL将使用Django的内置逃避过滤器。 autoescape的默认值为 True

The urlize filter also takes an optional parameter autoescape. If autoescape is True, the link text and URLs will be escaped using Django's built-in escape filter. The default value for autoescape is True.

我想使用这个参数,但文档中没有说明如何实际地将一个关键字参数传递给模板过滤器。是否可能,如果是,我该如何做?

I'd like to use this parameter, but the documentation says nothing about how to actually pass a keyword argument to a template filter. Is it possible, and if so, how do I do that?

推荐答案

显然 urlize 从当前autoescape设置中获取该关键字参数,所以去的方式看起来像

Apparently urlize gets that keyword argument from current autoescape settings, so the way to go seems like

{% autoescape off %}{{ value|force_escape|urlize }}{% endautoescape %}

(如果还想逃避价值)

这篇关于如何传递Django的urlize模板过滤器的autoescape参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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