urlencode过滤器在django模板中不起作用(urlencode filter is not working in django templates)

我在Apache下使用django。 当我在django模板中使用urlencode时,它根本没有编写像这样的{{value|urlencode}}这里是我完整的锚标签

<a href="/mysite/comment/{{i.comment_id|urlencode}}">Comment</a>

有人可以帮助吗? 有什么办法摆脱这个?

在此先感谢 - Vikram

I am using django under Apache. When I use urlencode in django template, its not at all enoding some thing like this {{value|urlencode}} Here is my complete anchor tag

<a href="/mysite/comment/{{i.comment_id|urlencode}}">Comment</a>

Can some one help on this? Is there any way to get rid of this?

Thanks in advance - Vikram

最满意答案

urlencode过滤器仅对网址中不安全的字符进行编码。 如果你想编码所有的字符,那么你将需要编写或找到一个不同的过滤器。

The urlencode filter only encodes characters that are unsafe to have in a URL. If you want to encode all characters then you will need to write or find a different filter for that.

urlencode过滤器在django模板中不起作用(urlencode filter is not working in django templates)

我在Apache下使用django。 当我在django模板中使用urlencode时,它根本没有编写像这样的{{value|urlencode}}这里是我完整的锚标签

<a href="/mysite/comment/{{i.comment_id|urlencode}}">Comment</a>

有人可以帮助吗? 有什么办法摆脱这个?

在此先感谢 - Vikram

I am using django under Apache. When I use urlencode in django template, its not at all enoding some thing like this {{value|urlencode}} Here is my complete anchor tag

<a href="/mysite/comment/{{i.comment_id|urlencode}}">Comment</a>

Can some one help on this? Is there any way to get rid of this?

Thanks in advance - Vikram

最满意答案

urlencode过滤器仅对网址中不安全的字符进行编码。 如果你想编码所有的字符,那么你将需要编写或找到一个不同的过滤器。

The urlencode filter only encodes characters that are unsafe to have in a URL. If you want to encode all characters then you will need to write or find a different filter for that.