views:

53

answers:

3

In my django application I have my URLS.PY configured to accept requests to /community/user/id and /community/user/id/ with:

url(r'^(?P<username>[\w-]+)/(?P<cardId>\d+)/$', 'singleCard.views.singleCard', name='singleCardView'),

I did this as some times people will add an ending "/" and I didn't want to raise a 404.

However parts of my javascript application sometime add a anchor tag in the form of:

/community/user/id#anchorIuseInJavscriptToDoSomething

The problem I have is Django will instantly rewrite the URL to:

/community/user/id/ 

with an ending / and remove the #anchorIuseInJavscriptToDoSomething

Id like it to rewrite it to:

/community/user/id#anchorIuseInJavscriptToDoSomething/

This way my javascript in the page can still see the anchor and work. How can adapt this regex to do this? I'm not very good at regex, and learnt this one by example...

A: 

The Browser should handle re-appending the anchor after the redirect. Your problem has nothing to do with Django.

hop
Any idea why it doesn't in Safari and if there is an other solution? Like for example configuring Django to accept both URLs but not to re-write them?
Tristan
@Tristan: it's a known issue with safari. there have been bugs filed against it already, but it couldn't hurt if you filed one too.
hop
btw, trying to include the anchor in the redirect will only shift the problem to ie8, iirc
hop
A: 

Why do you want to change it to /community/user/id#anchorIuseInJavscriptToDoSomething/? This is invalid. It should be /community/user/id/#anchorIuseInJavscriptToDoSomething. The element after the hash is not part of the URL and is not sent to the server.

Daniel Roseman
Some times a user will manually type in /community/user/id/with a ending slash. I don't want to return a 404 when they do.I do also need to be able to have a hash in there, so ideally I'd like to not rewrite the URL, but have both work
Tristan
A: 

you could make the trailing slash optional:

url(r'^(?P<username>[\w-]+)/(?P<cardId>\d+)/?$', 'singleCard.views.singleCard', name='singleCardView'),
Jason