我已经在django中实现了密码恢复功能。使用我的方法,新密码将发送到输入的电子邮件ID。当给出正确的电子邮件(数据库中存在的电子邮件ID)时,它可以正常工作。但是,如果给定的电子邮件ID不在数据库中,则会出现错误:'DoesNotExist at /forgotPassword/ UniversityDetails matching query does not exist.'
我该如何解决这个问题?
forgotPassword.html()
def forgotPassword(request):
if request.POST:
email=request.POST.get("email")
user = UniversityDetails.objects.get(email=email)
if(not user):
print "No user"
return render_to_response("forgotPassword.html")
else:
newPassword = user.password
send_mail('Password Recovery', 'The password for your site is '+ newPassword, '[email protected]',
['[email protected]'], fail_silently=False)
return render_to_response("passwordRecovery.html")
return render_to_response('forgotPassword.html')
html <form name="forgotPassword" method="POST" id="myFormid" action="http://10.1.0.90:8080/forgotPassword/">
<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" />
</div>
</form >
最佳答案
try:
user = UniversityDetails.objects.get(email=email)
except UniversityDetails.DoesNotExist:
user = None
我还看到您以纯文本形式存储密码(安全性高,请注意!)。考虑改用内置的身份验证系统。关于python - 匹配查询不存在Django中的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5508888/