I'm writing a simple auth system to login (and logout) users. The username is an email address, which looks up an email field.
I'm using:
user = User.objects.get(email__exact=email)
# if user obj exists
if user:
# if authenticate
if authenticate(user, email, password):
# create session
request.session['user'] = user
# redir
return HttpResponseRedirect('/home/')
else:
return HttpResponseRedirect('/home/login/')
# no user obj found? (no email found actually)
else:
# redir
return HttpResponseRedirect('/home/')
to find if a user exists, however if a user is not found Django throws an error:
User matching query does not exist.
All I want to do is see if that query matches a result. How do I count rows?