Django 中的匹配查询不存在错误

2024-02-16

我在 django 中实现了密码恢复功能。使用我的方法,新密码将发送到输入的电子邮件 ID。当给出正确的电子邮件(数据库中存在的电子邮件 ID)时,它可以正常工作。但是当给定的电子邮件 ID 不在数据库中时,会出现错误:
'DoesNotExist at /forgotPassword/ UniversityDetails matching query does not exist.'

我该如何解决这个问题?

忘记密码.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] /cdn-cgi/l/email-protection',
    ['[email protected] /cdn-cgi/l/email-protection'], 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

我还看到您以明文形式存储密码(这是一个很大的安全禁忌!)。考虑使用内置的身份验证系统。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django 中的匹配查询不存在错误 的相关文章

随机推荐