如何让Django urls.py识别url中的#(hash)?

时间:2023-02-07 04:37:45

Let's say I want the following url to get matched with a django view through urls.py: www.mysite.com/cake/#vanilla

假设我希望以下网址通过urls.py与django视图匹配:www.mysite.com/cake/#vanilla

In urls.py I have something like this:

在urls.py我有这样的事情:

url('^cake/#.*/$', app.views.view ),

So basically I want all urls that start with root: www.mysite.com/cake/#, to be handled by this view. However, django urls seems to treats # as %23, so instead all urls with root www.mysite.com/cake/%23 is handled by that view. How can I get the hash sign in url('^cake/#.*/$', app.views.view ), to be treated like an actual hash sign instead of a %23?

所以基本上我想要所有以root开头的网址:www.mysite.com/cake/#,由这个视图处理。但是,django urls似乎将##视为%23,因此所有具有根www.mysite.com/cake/%23的URL都由该视图处理。如何将url('^ cake /#.*/$',app.views.view)中的哈希符号视为实际哈希符号而不是%23?

Thanks for any help!

谢谢你的帮助!

1 个解决方案

#1


3  

You need to force your users to use IE7 from winetricks. It's the only browser that has the bug of sending the hash and stuff in the HTTP request :)

您需要强制用户使用winetricks中的IE7。这是唯一一个在HTTP请求中发送散列和内容的bug的浏览器:)

If it has been fixed, then you need to force your users to use IE7 from winetricks of last year's version.

如果它已经修复,那么你需要强迫你的用户使用去年版本的winetricks中的IE7。

As Adam stated, browsers should not send the hash part to the server. Using the hash in the url is common for websites like deezer because it lets the user navigate without reloading the page (all navigation is handled in javascript). This allows navigation without interuption/reload of the music player which is in flash.

正如Adam所说,浏览器不应该将散列部分发送到服务器。在网址中使用网址中的哈希是常见的,因为它允许用户在不重新加载页面的情况下导航(所有导航都在javascript中处理)。这允许导航而无需闪存中的音乐播放器的中断/重新加载。

If you want to enable hash browsing, then you can use a plugin like: http://tkyk.github.com/jquery-history-plugin/

如果你想启用哈希浏览,那么你可以使用如下插件:http://tkyk.github.com/jquery-history-plugin/

#1


3  

You need to force your users to use IE7 from winetricks. It's the only browser that has the bug of sending the hash and stuff in the HTTP request :)

您需要强制用户使用winetricks中的IE7。这是唯一一个在HTTP请求中发送散列和内容的bug的浏览器:)

If it has been fixed, then you need to force your users to use IE7 from winetricks of last year's version.

如果它已经修复,那么你需要强迫你的用户使用去年版本的winetricks中的IE7。

As Adam stated, browsers should not send the hash part to the server. Using the hash in the url is common for websites like deezer because it lets the user navigate without reloading the page (all navigation is handled in javascript). This allows navigation without interuption/reload of the music player which is in flash.

正如Adam所说,浏览器不应该将散列部分发送到服务器。在网址中使用网址中的哈希是常见的,因为它允许用户在不重新加载页面的情况下导航(所有导航都在javascript中处理)。这允许导航而无需闪存中的音乐播放器的中断/重新加载。

If you want to enable hash browsing, then you can use a plugin like: http://tkyk.github.com/jquery-history-plugin/

如果你想启用哈希浏览,那么你可以使用如下插件:http://tkyk.github.com/jquery-history-plugin/