Combinando el codigo de razpetia con el mio fi vista log_in queda de la siguiente manera por si le sirve a alguien:
Código PHP:
def log_in(request):
if request.user.is_authenticated():
return HttpResponseRedirect('/')
url_next = request.GET.get('next', None)
if request.method == 'POST':
login_form = AuthenticationForm(request.POST)
url_next = request.POST.get('next', None)
if login_form.is_valid:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
if url_next is not None:
return HttpResponseRedirect(url_next)
else:
return HttpResponseRedirect('/')
else:
pass # usuario no activado
else:
login_form = AuthenticationForm()
return render_to_response('authentication/login.html', {'next': url_next, 'login_form': login_form},
context_instance=RequestContext(request))