开发者

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

开发者 https://www.devze.com 2023-02-13 06:51 出处:网络
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:

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>
开发者_JAVA百科

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?


Maybe try to write Your own custom filter

0

精彩评论

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

关注公众号