【问题标题】:Prevent URL encoding that is removing equals signs from URL防止从 URL 中删除等号的 URL 编码
【发布时间】:2018-07-02 16:17:02
【问题描述】:

在 Django/React 应用程序上工作。我有一些如下所示的验证电子邮件链接:

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 = '%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')),

【问题讨论】:

    标签: django reactjs react-router-dom


    【解决方案1】:

    这些变量在 GET 请求中应该是 query parameters。当您构建链接时,您需要在某个地方添加一个问号,将 URL 与查询字符串分开:

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

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

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 2023-02-07
      • 1970-01-01
      • 2014-09-26
      • 2015-11-30
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2018-04-04
      相关资源
      最近更新 更多