Django模板上的URL编码

jdt*_*toh 20 html django django-templates url-encoding

我有这个锚链接:

<a href="/question/tag/1/1/?list_id={{title}}">{{title}}</a>
Run Code Online (Sandbox Code Playgroud)

有时,这个标题有一些内容+(添加运算符),如:"Django + Python"

但是当它直接放在锚链接上时,交付的网址将是:

http://127.0.0.1:8080/question/tag/1/1/?list_id=Django + Python
Run Code Online (Sandbox Code Playgroud)

这将最终导致检索问题,因为url解码器认为list_id GET = DjangoPython.

那么,有谁知道如何避免这个问题?请注意,我不想将锚链接更改为输入按钮.

jdt*_*toh 57

代替

{{ title }}
Run Code Online (Sandbox Code Playgroud)

{{title|urlencode}}
Run Code Online (Sandbox Code Playgroud)

  • https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#urlencode (2认同)