Django用户身份验证:登录后不重定向

时间:2022-10-20 08:30:02

My website has a front page that has a link to a forum. Access to the forum requires that the user be logged in. I have therefore given the view show_forum the decorator: @login_required. When the user clicks the forum link, they are correctly redirected to the login page. Once the user has logged in they are, however, taken back to the front page, not to the forum page. If the user now (being logged in) clicks the forum link then he is taken directly to the forum page.

我的网站有一个首页,有一个论坛的链接。进入论坛需要用户登录。因此,我为视图show_forum指定了decorator: @login_required。当用户单击论坛链接时,它们会被正确地重定向到登录页面。但是,一旦用户登录了,就会返回到首页,而不是论坛页面。如果用户现在(正在登录)单击论坛链接,那么他将被直接带到论坛页面。

Via Firebug, I can see that the url is getting the correct 'next' parameter. Any hints or things that I should look for?

通过Firebug,我可以看到url获得了正确的“next”参数。有什么需要我帮忙的吗?

1 个解决方案

#1


1  

My most common issue with the login_required decorator is that I forget to redirect to the next parameter while having a custom login view in place. In other words, the page gets built up in segments, and after a while the login feature gets added. By default, this view redirects to a default index page (what you probably equals to your "front page").

login_required decorator最常见的问题是,我在使用自定义登录视图时忘记重定向到下一个参数。换句话说,页面以分段的形式构建,一段时间后会添加登录功能。默认情况下,该视图将重定向到默认索引页(您可能等于您的“首页”)。

What this boils down to is: do you have something like the following in your /accounts/login/ view?

这可以归结为:您的/account /login/ view中是否有以下内容?

return HttpResponseRedirect(request.GET.get('next', settings.LOGIN_REDIRECT_URL))

#1


1  

My most common issue with the login_required decorator is that I forget to redirect to the next parameter while having a custom login view in place. In other words, the page gets built up in segments, and after a while the login feature gets added. By default, this view redirects to a default index page (what you probably equals to your "front page").

login_required decorator最常见的问题是,我在使用自定义登录视图时忘记重定向到下一个参数。换句话说,页面以分段的形式构建,一段时间后会添加登录功能。默认情况下,该视图将重定向到默认索引页(您可能等于您的“首页”)。

What this boils down to is: do you have something like the following in your /accounts/login/ view?

这可以归结为:您的/account /login/ view中是否有以下内容?

return HttpResponseRedirect(request.GET.get('next', settings.LOGIN_REDIRECT_URL))