Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urlencode filter is not working in django templates

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

like image 484
vkrams Avatar asked Jan 24 '26 22:01

vkrams


2 Answers

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.

like image 185
Ignacio Vazquez-Abrams Avatar answered Jan 26 '26 13:01

Ignacio Vazquez-Abrams


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

like image 39
acpmasquerade Avatar answered Jan 26 '26 14:01

acpmasquerade