Django模板上的URL编码 [英] URL encoding on Django Template
本文介绍了Django模板上的URL编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个锚链接:
<a href="/question/tag/1/1/?list_id={{title}}">{{title}}</a>
有时,此标题带有+(添加运算符)的某些内容,例如:
Django + Python
Sometimes, this title has some content with + (add operator) like: "Django + Python"
但是将其直接放置在锚链接上时,传递的网址将是:
But when it is directly placed on anchor links, the url delivered will be:
http://127.0.0.1:8080/question/tag/1/1/?list_id=Django + Python
这最终会导致检索出现问题,因为url解码器认为list_id GET = DjangoPython。
Which will eventually cause problem on the retrieval as the url decoder thought the list_id GET = DjangoPython.
所以,有人知道吗如何避免这个问题?请注意,我不想更改输入按钮的锚点链接。
So, does anyone knows how to avoid this issue? Note that I do not want to change anchor links to input buttons.
推荐答案
代替
{{ title }}
do
{{title|urlencode}}
这篇关于Django模板上的URL编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文