tags:

views:

39

answers:

1

Hello, 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

+1  A: 

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

piquadrat
thanks alot, at where shall I be putting this method ? models.py of my app?
Hellnar
it's a view, so it probably feels most at home in a views.py :)
piquadrat