开发者

In Django's "login" built in app, how do I make it redirect to the home page when the user is already logged in?

(r'^login/?$',login,{'开发者_JAVA百科template_name':'login.html', 'authentication_form':CustomAuthenticationForm}),

Right now, I do this. I utilize Django's login system.

But, when I'm logged in, it still redirects me to the login page.


Usually, you don't ever go to the login page. Ever.

You use the @login_required decorator on each relevant view function.

The decorator redirects to the login page, then redirects back to the originally requested page.

There's no reason to ever bookmark, link to or visit the login page.


There are two options, depending on the behavior you want.

  1. As S. Lott says, just don't send people over to the login page from the get go, only use the decorator or is_authenticated() call and redirect users there when needed, and you go "around" your problem.

  2. If for some reason people are getting to your login page (landing page, deep linking and so on), you can use the is_authenticated on your view and manually redirect them when they do get there. I've used this in the past when I implemented SSO with Facebook for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜