Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

python - How to change particular database columns value in in django framework

Hi i am try to solve reset password through dynamically .. what i doing some one register my form it will store in my database all fields value storing, But i have give one more connection just like reset password through by mail if some one submit email it will go to email id and he will link their for reset password in that page i am password and conform password, this form it should go to the same register database in that particular field is that password, conform password only change not other value .. but in my code what happening updating password but remains column values showing null

View.py

def reset_password(request,id):

if request.method == 'POST' and Register.objects.all():
        if Register.objects.get(id=id):
            print('re')
            password = request.POST['password']
            password1 = request.POST['password1']
            # Validation
            #reg = Register.objects.filter(password='65789')
            #for obj in reg:
             #   obj.password1 = '65789'
              #  obj.save()

            arr = Register(id=id,password=password,password1=password1)
            #user = Register(id=id,arr)
            arr.save()
            return HttpResponse('New password succesfully stored ')

return render(request,'reset_password.html')

##Mysql Database ..in that 24 id please check it you will get idea, i dnot want reset django frame work that why i am trying this way please any one help me enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From what I understand of your question you want to send a Password reset link to the user.
Django already has a simple way to do this. You need to use the following views:-

  • PasswordResetView
  • PasswordResetDoneView
  • PasswordResetConfirmView
  • PasswordResetCompleteView

here is a tutorial you might find helpful.
To answer your actual question though something like this should work:-

register_obj = Register.objects.get(id=id)
register_obj.password = new_password
register_obj.password1 = new_password
register_obj.save()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...