本文介绍了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"
但是当直接放在锚链接上时,传递的url是:
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 }}
做
{{title|urlencode}}
这篇关于Django 模板上的 URL 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!