如何在不通过 GET 转换的情况下按原样传递完整数据?

How to pass full data as it is without getting converted via GET?

我正在尝试使用以下代码通过 js 操作我的表单的操作:

form.action = "{% url 'search.html' phrase='developer' %}"

问题是,它将我的数据转换为奇怪的符号,而不是按原样传递。

http://localhost:8000/%7B%%20url%20'search.html'%20phrase='developer'%20%%7D?

如何避免这种转换?

The problem is, it converts my data to weird signs instead of passing it as it is.

,它不会转换任何东西。这里简单的用{% url 'search.html' phrase='developer' %}作为真正的URL,因为URL不能用{%等作为字符,它使用 percent encoding [wiki].

确实,如果您使用 url-encode-decode 之类的工具,那么您会发现它会将其解码为 {% url 'search.html' phrase='developer' %}

发生这种情况的原因是因为您显然没有 呈现模板的那部分。例如,如果您使用 JavaScript 文件作为静态文件,就是这种情况。

因此您应该确保 {% url … %} 部分位于 模板 中:模板引擎将 转换 [=33] 的文件=] 这到 URL,而不是在 Django 从不将它传递给模板引擎的(静态)文件中。