匹配查询不存在Django中的错误 [英] matching query does not exist Error in Django

查看:105
本文介绍了匹配查询不存在Django中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在django中实现了密码恢复功能。使用我的方法,新密码将被发送到他输入的电子邮件ID。当我给出正确的电子邮件(数据库中存在的电子邮件ID)时,它的工作正常。但是当我给出一个不在数据库中的电子邮件ID时,它会给我这个错误'DoesNotExist at / forgotPassword /



大学详细信息匹配查询不存在。有人可以帮忙解决这个问题。将粘贴我的代码在这里。有人可以帮我解决这个问题。



forgotPassword.html()

  def forgotPassword(request):
if request.POST:
email = request.POST.get(email)
user = UniversityDetails.objects
如果(不是用户):
打印没有用户
返回render_to_response(forgotPassword.html)
else:
newPassword = user.password
send_mail('Password Recovery','您的网站的密码是'+新密码''rv_nair@gmail.com',
['rv_ks@gmail.com'],fail_silently =
返回render_to_response(passwordRecovery.html)
返回render_to_response('forgotPassword.html')

html

 < form name =forgotPasswordmethod = POSTid =myFormidaction =http://10.1.0.90:8080/forgotPassword/> 
< div style =float:center; width:100%; color:#0000A0>
输入您的电子邮件ID< / label>< br /> < input type =textname =emailsize =25/>
< input type =submitvalue =提交/>
< / div>

< / form>


解决方案

  try: 
user = UniversityDetails.objects.get(email = email)
除了UniversityDetails.DoesNotExist:
user = None

我也看到你正在以明文形式存储你的密码(一个很大的安全性,不要!)。为什么不使用内置的验证系统?


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.

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, 'rv_nair@gmail.com',
    ['rv_ks@gmail.com'], 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

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?

这篇关于匹配查询不存在Django中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆