简体   繁体   中英

django-registration, fix for a glitch

I am using django-registration version 0.8

I use the default django-registration and Django auth system without 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM