Django URL 模式包含#
Django URL pattern to include a #
我在使用 URL 模式时遇到问题。
URL格式如下:
/API#access_token=<string>&expires_in=<timestamp>
不幸的是,我无法更改#access_token=&expires_in= 部分,因为这超出了我的控制范围,我只需要让我这边的代码正常工作即可。
我尝试了多种不同的模式,下面概述了其中的一些模式。这是我的第一个 Django 项目,如有任何建议和指点,我们将不胜感激。
url(r'^API#access_token=(?P<token_info>\w+)&expires_in(?P<time>\d+)$'
url(r'^API#(?P<tokens>\w+)$'
url(r'^API/#(?P<tokens>\w+)&(?P<expiration>\d+)$'
问题是锚 #
,也称为片段标识符,没有被浏览器发送到服务器。正则表达式无法捕获不存在的内容。来自 wikipedia article on the fragment identifier:
The fragment identifier functions differently than the rest of the
URI: namely, its processing is exclusively client-side with no
participation from the web server — of course the server typically
helps to determine the MIME type, and the MIME type determines the
processing of fragments. When an agent (such as a Web browser)
requests a web resource from a Web server, the agent sends the URI to
the server, but does not send the fragment. Instead, the agent waits
for the server to send the resource, and then the agent processes the
resource according to the document type and fragment value.
解决此问题的唯一方法是在客户端解析 JavaScript 中的片段并将其作为单独的异步请求发送。对于 GET 请求,您可以将片段作为查询参数发送(在剥离哈希后)或将其作为自定义值放入 header。
我在使用 URL 模式时遇到问题。
URL格式如下:
/API#access_token=<string>&expires_in=<timestamp>
不幸的是,我无法更改#access_token=&expires_in= 部分,因为这超出了我的控制范围,我只需要让我这边的代码正常工作即可。
我尝试了多种不同的模式,下面概述了其中的一些模式。这是我的第一个 Django 项目,如有任何建议和指点,我们将不胜感激。
url(r'^API#access_token=(?P<token_info>\w+)&expires_in(?P<time>\d+)$'
url(r'^API#(?P<tokens>\w+)$'
url(r'^API/#(?P<tokens>\w+)&(?P<expiration>\d+)$'
问题是锚 #
,也称为片段标识符,没有被浏览器发送到服务器。正则表达式无法捕获不存在的内容。来自 wikipedia article on the fragment identifier:
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the web server — of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a Web browser) requests a web resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.
解决此问题的唯一方法是在客户端解析 JavaScript 中的片段并将其作为单独的异步请求发送。对于 GET 请求,您可以将片段作为查询参数发送(在剥离哈希后)或将其作为自定义值放入 header。