[Django]-URL Fragments in Redirect for LoginRequiredMixin

3👍

The issue is the way the browser interprets the login URL. You want it to be intepreted like this:

/accounts/login/?next="/spa_home/#price_requests/68"

but actually, it is seen like this:

"/accounts/login/?next=/spa_home/"#price_requests/68

In other words, the hash is seen as attaching to the login URL itself, not the redirect parameter.

The way to fix this is to quote the parameter:

urllib.quote('/spa_home/#price_requests/68')

which gives you /spa_home/%23price_requests/68, which will be interpreted correctly.

Leave a comment