urlencode过滤器在django模板中不起作用

vkr*_*ams 1 django templates urlencode

我在Apache下使用django.当我urlencode在django模板中使用时,它根本不会包含这样的东西{{value|urlencode}}这里是我完整的锚标签

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

有人可以帮忙吗?有没有办法摆脱这个?

在此先感谢 - 维克拉姆

Ign*_*ams 5

urlencode过滤器只编码是不安全的有在URL中的字符.如果要对所有字符进行编码,则需要为此编写或查找不同的过滤器.


acp*_*ade 5

根据 django 文档 - / 在默认情况下不会转义。要转义 / 或其他字符,请使用可选参数:

{{ value|urlencode:"" }}
Run Code Online (Sandbox Code Playgroud)

更多详细信息 - https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#std:templatefilter-urlencode