Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
django user; change password from shell

update django password

general changes

To use in dev environments

  • after python manage.py shell
from django.contrib.auth.models import User

# dev environ with only a few users
l = User.objects.all() 

# show user list
print(l)

# get the 1st user
u = l[0]

# set the password
u.set_password('123') # for dev
u.save()

with custom user

  • Only differs by initial import on 1st line
from tworaven_apps.raven_auth.models import User

# dev environ with only a few users
l = User.objects.all() 

# show user list
print(l)

# get the 1st user
u = l[0]

# set the password
u.set_password('123') # for dev
u.save()
@adigunsherif

This comment has been minimized.

Copy link

@adigunsherif adigunsherif commented Aug 14, 2020

Instead of showing all users, you can search by id, username or email

l = User.objects.get(username='someone')

or

l = User.objects.get(email='someone@someplace.com')

or

l = User.objects.get(id=3)

in this case, Username or email must be unique to get object

@Izuguchi

This comment has been minimized.

Copy link

@Izuguchi Izuguchi commented Nov 13, 2020

Thank you very much!!

@Luis1Jovany

This comment has been minimized.

Copy link

@Luis1Jovany Luis1Jovany commented Jan 3, 2021

Thanks! This helped me.

@Pragyanshu-rai

This comment has been minimized.

Copy link

@Pragyanshu-rai Pragyanshu-rai commented Apr 1, 2021

Thank you very much!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment