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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -