matching query does not exist Error in Django


I have implemented a password recovery functionality in django. With my method the new password will be sent to his email id entered. And its working fine when i give the correct email (e-mail id which exists in the database). But when i give an email id which is not in the database, it gives me this error 'DoesNotExist at /forgotPassword/

UniversityDetails matching query does not exist.'. Can somebody help to solve this. Will paste my code here. Can somebody help me to solve this problem.


def forgotPassword(request):
    if request.POST:
        user = UniversityDetails.objects.get(email=email)
        if(not user):
            print "No user"
            return render_to_response("forgotPassword.html")
            newPassword = user.password
            send_mail('Password Recovery', 'The password for your site is '+ newPassword, '',
    [''], fail_silently=False)   
            return render_to_response("passwordRecovery.html")
    return render_to_response('forgotPassword.html')


<form name="forgotPassword" method="POST" id="myFormid" action="">
<div style="float:center;width:100%;color:#0000A0">
 Enter your E-mail ID</label><br/> <input type="text" name="email" size="25" /> 
 <input type="submit" value="Submit" />

</form >
10/19/2015 7:15:18 AM

Accepted Answer

    user = UniversityDetails.objects.get(email=email)
except UniversityDetails.DoesNotExist:
    user = None

I also see you're storing your passwords in plaintext (a big security no-no!). Why don't you use the built-in auth system?

4/1/2011 3:47:44 AM

I also had this problem. It was caused by the development server not deleting the django session after a debug abort in Aptana, with subsequent database deletion. (Meaning the id of a non-existent database record was still present in the session the next time the development server started)

To resolve this during development, I used


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow