防止从 URL 中删除等号的 URL 编码

Prevent URL encoding that is removing equals signs from URL

正在开发 Django/React 应用程序。我有一些验证电子邮件 link 如下所示:

https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92

在开发环境中这工作正常,但现在我准备好投入生产,它不工作。当我点击它时,它会将其转换为:

https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92/

这会阻止 react-router-dom 匹配正确的 URL,因此 Web 应用程序的一部分无法正确加载。

link 使用以下内容构造。

link = '%s/auth/security_questions/f=%s&i=%s&k=%s' % \
('https://test.example.com', 'ru', user.id, user.key)

此外,这里是 url() 正在捕获的路线:

url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),

这些变量应该在 GET 请求中 query parameters。当您构造 link 时,您需要在 URL 与查询字符串之间的某个地方有一个问号:

https://test.example.com/auth/security_questions/?f=ru&i=101083&k=7014c315...
                                                 ^
                                                 |___ here

= 到 url 编码的 %3D 等的转换是正确的,并且是等效的。有时变量直接是 URL 的一部分,但在这种情况下,网络应用程序不使用 & 分隔的 key/value 对。