from django.core.urlresolvers import reverse
from django.shortcuts import redirect

def login(request):
    if request.session.get('user'):
        return redirect(reverse('name-of-url'))
Django and urls.py: How do I HttpResponseRedirect via a named url?