Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using User.objects.get_or_create() gives invalid password format in django?

python manage.py shell

>>> from django.contrib.auth.models import User
>>> u=User.objects.get_or_create(username="testuser2",password="123")
>>> u
(<User: testuser2>, True)

seems it created the User properly. but when I logged into admin at http://127.0.0.1:8000/admin/auth/user/3/, I see this message for password Invalid password format or unknown hashing algorithm.

Screenshot is attached too. why is it this way and how to create User objects from shell. I am actually writing a populating script that create mulitple users for my project?

enter image description here

like image 324
brain storm Avatar asked Apr 07 '14 22:04

brain storm


1 Answers

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()
like image 54
Sohan Jain Avatar answered Sep 20 '22 09:09

Sohan Jain