开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜