[Django]-Django AttributeError: 'User' object has no attribute 'set_password' but user is not override

4👍

You need to inherit from AbstractUser to get access to set_password attribute. Instead of using models.Model use:

from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    ...

Your User model is not the same as django’s User model.

Reference custom user model

2👍

from django.contrib.auth.hashers import make_password
replace
user.set_password(password) by user.password = make_password(‘password’)
it clear and work for me.

0👍

The User model in Django has .set_password but if you made your own you should try OneToOneField(User) from there you just have to make sure you save both in the views.

user_form = UserForm(data=request.POST)
if user_form.is_valid():
    user = user_form.save()
    user.set_password(user.password)
    profile = user.userprofile
    profile.bio = request.POST['bio']
    profile.save()

Leave a comment