开发者

urlencode filter is not working in django templates

I am u开发者_开发知识库sing 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


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.


As per the django documentation - / is not escaped in default case. To escape / or other characters as well, use the optional parameter as

{{ value|urlencode:"" }}

more details - https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#std:templatefilter-urlencode

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜