开发者

django-registration, fix for a glitch

I am using django-registration version 0.8

I use the default django-registration and Django auth system w开发者_开发百科ithout any tweak. I did notice a small glitch, once I log in as a user, if I go to the /accounts/login/ , I still get the login entry form, how can I change that it redirect a logged in user to the main root url / instead of bringing this form once again ?

Thanks


You can wrap Django's login view and do the check for already authenticated users there:

from django.contrib.auth.views import login
from django.http import HttpResponseRedirect

def mylogin(request, **kwargs):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        return login(request, **kwargs)

Then simply use this view instead of django.contrib.auth.views.login in your urls.py

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜