0

When loading a page, I would like the user to be sent directly to a part of it, called #town-center.

I've written the following code :

url(r'^(?i)(?P<town_slug>[-\w]+)/', RedirectView.as_view(permanent=False, url='#town-center')), # adds the "town-center" anchor to reposition the browser when displaying the town
url(r'^(?i)(?P<town_slug>[-\w]+)/#$', views.town_map, name='town_map'),

This works in adding #town-center to the current URL, but it fails because the first pattern always gets picked up, and it loops.

The exact error I'm getting from Firefox is : "The page isn't redirecting properly".

How can I make this work ?

Brachamul
  • 1,886
  • 2
  • 21
  • 34

1 Answers1

1

You can't process url part, that goes after #, at server side. Because it is for browser side only, it will be not send to server.

So do the redirect at browser side, using javascript.

Also look https://stackoverflow.com/a/3664324/821594

Community
  • 1
  • 1
stalk
  • 11,934
  • 4
  • 36
  • 58