31👍
✅
You need to use the User.set_password
method to set a raw password.
E.g.,
from django.contrib.auth.models import User
user, created = User.objects.get_or_create(username="testuser2")
user.set_password('123')
user.save()
6👍
Almost correct except we don’t want to set password of existing users
from django.contrib.auth.models import User
user, created = User.objects.get_or_create(username="testuser2")
if created:
# user was created
# set the password here
user.set_password('123')
user.save()
else:
# user was retrieved
👤Yash
- Disable caching for a view or url in django
- Django 2.0: sqlite IntegrityError: FOREIGN KEY constraint failed
1👍
As mentioned in the documentation.
The most direct way to create users is to use the included create_user() helper function.
from django.contrib.auth.models import User
user = User.objects.create_user(username="testuser2",password="123")
- Passing an object created with SubFactory and LazyAttribute to a RelatedFactory in factory_boy
- There are errors when I install django by git?
- How to include excluded rows in RETURNING from INSERT … ON CONFLICT
- Decoder JPEG not available error when following Django photo app tutorial
Source:stackexchange.com