开发者

Redirecting pages in Django with regular expressions?

I am working on a very Ajax-heavy site that uses History.js, which basically ports HTML5's pushState and replaceState to HTML4.

Anyways, in HTML4 browsers, the pseudo-url is added after the hash tag in an url.

I want to redirect any requests to any page with a hash in the url to the url开发者_如何学Python after the hash.

For example, a user puts this into their address bar:

localhost:8000/bio#./contact

will be redirected to:

localhost:8000/contact

This of course would only be so that if a user were to bookmark my site and return to it, or post the link to a web site, the returning url would start out cleaner.

I think I have the regex figured out:

r'^$/%23.(?P<hash_url>\d+) # %23 is "#"

i just need to know how to redirect...

Thanks in advance


Django doesn't have access to whatever is after the hashtag. This is by design (HTTP Protocol). The only way to do it, is to have javascript on the page that looks for hashtags, and redirects as needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜