python - str object has no attribute '*' -
i wanna update password of user have error
str object has no attribute '*'
if request.method == 'post': form = resetpwdform(request.post) if form.is_valid(): email = form.cleaned_data['email'] passwordnew = form.cleaned_data['passwordnew'] passwordconfirm = form.cleaned_data['passwordconfirm'] #actual password ok if passwordconfirm == passwordnew: #new password match confirm u = request.post.get('username', '') u.set_password(passwordnew) u.save()
the problem on line u.set_password(passwordnew)
.
the u
not instance of user
model intended string value coming post form. have user
instance due username got in form field
u = user.objects.get(username=request.post.get('username', ''))
you have handle situation when there no such user given username
try: u = user.objects.get(username=request.post.get('username', '')) #setting password , whatever... except user.doesnotexist: #do
Comments
Post a Comment