Django: How do I quote and unquote special characters in the same template?

1.1k views Asked by At

My app has a 'tags' functionality. I want to allow special characters (like '+' and '.') and, as a result, I need to escape these characters in the url:

<a href="/tags/{{ tag|ESCAPED }}/"></a>

But need them unescaped when printing inside of the "a" tag:

<a href="">{{ tag|UNESCAPED }}</a>

The problem is, I can't seem to find the proper filter to escape the special chars (I've tried "urlencode", but this doesn't seem to do anything, at least with '.'). I've thought about translating special chars inside of my view, but then I would still have to unquote/unescape them when printing them inside of the "a" tag. So how does one go about doing this?

1

There are 1 answers

0
robos85 On

Maybe try to write Your own custom filter