URL Fragments in Redirect for LoginRequiredMixin

前端 未结 1 620
日久生厌
日久生厌 2020-12-20 00:21

I am using django-braces\'s LoginRequiredMixin in a Django 1.6 project. This mixin replicates Django\'s login_required decorator.

I have a view that uses the

相关标签:
1条回答
  • 2020-12-20 00:44

    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.

    0 讨论(0)
提交回复
热议问题