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.
- [Django]-How to filter using an expression in Django
- [Django]-Django save override ImageField handling
- [Django]-How to tell Django model that only one or other field must be not empty?
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()
- [Django]-Reverse for ''*'' with arguments '()' and keyword arguments '{}' not found
- [Django]-Is this how django does Single Table Inheritance?
- [Django]-PIP cannot install Django inside VIrtualenv
- [Django]-Decorating a sitemap view in Django
Source:stackexchange.com