¿Redirigir páginas en Django con expresiones regulares?

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 after the hash.

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


will be redirected to:


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...

Gracias por adelantado

preguntado el 27 de agosto de 11 a las 17:08

1 Respuestas

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.

Respondido 27 ago 11, 21:08

Hmm, ok well alternatively, is there a way that i can use javascript to change the urls in history - in HTML4 and 5? The only concern I have is that all of these pages exist at their respective urls, but can be loaded from any other page because of Ajax. I was hoping to also have this site accessible to those without javascript, and also provide a bridge between users who might view this site with javascript and thoes who dont. In short, my worry is that a user will see the link somewhere to: mysite.com/bio/#./blog/12/12/11/ and enter it into their browser and only get mysite.com/bio - Austin

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.