开发者

django-registration, fix for a glitch

开发者 https://www.devze.com 2022-12-20 03:23 出处:网络
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 asmall glitch, once I log in as a user, if Igo t

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

精彩评论

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