I’m trying to make a user login view, and It keep failing. This is my code:
def userLogin(request):
if request.method == 'POST':
form = AuthenticationForm(request.POST)
if form.is_valid():
user = authenticate(username = request.POST['username'], password = request.POST['password'])
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect("/success")
else:
return render_to_response('/home/dockedin/webapps/linked/myproject/templates/index.html', {'outcome':'Account Disabled'}, context_instance= RequestContext(request))
else:
return render_to_response('/home/dockedin/webapps/linked/myproject/templates/index.html', {'outcome':'Invalid Login'}, context_instance= RequestContext(request))
else:
return render_to_response('/home/dockedin/webapps/linked/myproject/templates/index.html', {'outcome':'FORM NOT VALID?'}, context_instance= RequestContext(request))
else:
form = AuthenticationForm()
return render_to_response('/home/dockedin/webapps/linked/myproject/templates/index.html', {'form':form}, context_instance= RequestContext(request))
Basically, I keep getting “FORM NOT VALID” printed in my site and I have no clue why. Help Please? Thank you
Try to print the
form.errorsto see why the validation fails.BTW, is there a reason that you don’t use the built-in
django.contrib.auth.views.loginview?