How to reset Django admin password?

How to reset Django admin password?

I am using Django (version 1.3) and have forgotten both admin username and password. How to reset both?
And is it possible to make a normal user into admin, and then remove admin status?


Answer 1:

python changepassword <user_name>

see docs

Answer 2:

  1. python createsuperuser will create another superuser, you will be able to log into admin and rememder your username.
  2. Yes, why not.

To give a normal user privileges, open a shell with python shell and try:

from django.contrib.auth.models import User
user = User.objects.get(username='normaluser')
user.is_superuser = True

Answer 3:

You may try through console:

python shell

then use following script in shell

from django.contrib.auth.models import User

will list you all super users on the system. if you recognize yur username from the list:

usr = User.objects.get(username='your username')
usr.set_password('raw password')

and you set a new password (:

Answer 4:

You can create a new superuser with createsuperuser command.

Answer 5:

This is very good question.

python changepassword user_name

Example :-

python changepassword mickey

Answer 6:

new setup should first run python createsuperuser to create user. It seems like there is no default username password to login into admin.

Answer 7:

One of the best ways to retrieve the username and password is to view and update them. The User Model provides a perfect way to do so.

In this case, I’m using Django 1.9

  1. Navigate to your root directory i,e. where you “” file is located using your console or other application such as Git.
  2. Retrieve the Python shell using the command “python shell”.
  3. Import the User Model by typing the following command
    “from django.contrib.auth.models import User”
  4. Get all the users by typing the following command
    “users = User.objects.all()”
  5. Print a list of the users
    For Python 2 users use the command “print users”
    For Python 3 users use the command “print(users)”
    The first user is usually the admin.

  6. Select the user you wish to change their password e.g.

    "user = users[0]"

  7. Set the password


  8. Save the new password


Start the server and log in using the username and the updated password.

Answer 8:

You may also have answered a setup question wrong and have zero staff members. In which case head to postgres:

obvioustest=# \c [yourdatabasename]
obvioustest=# \x
obvioustest=# select * from auth_user;
-[ RECORD 1 ]+-------------
id           | 1
is_superuser | f
is_staff     | f

To fix, edit directly:

update auth_user set is_staff='true' where id=1;

Answer 9:

You may try this:

1.Change Superuser password without console

python changepassword <username>

2.Change Superuser password through console

enter image description here
enter image description here

Answer 10:

If you forgot create admin user first build one with createsuperuser command on then change the password.

Answer 11:

In case you do not know the usernames as created here. You can get the users as described by @FallenAngel above.

python shell 
from django.contrib.auth.models import User
usrs = User.objects.filter(is_superuser=True)
#identify the user
your_user = usrs.filter(username="yourusername")[0]
#youruser = usrs.get(username="yourusername")
#then set the password

However in the event that you created your independent user model. A simple case is when you want to use email as a username instead of the default user name. In which case your user model lives somewhere such as your_accounts_app.models then the above solution wont work.
In this case you can instead use the get_user_model method

from django.contrib.auth import get_user_model 
super_users = get_user_model().objects.filter(is_superuser=True)
#proceed to get identify your user
# and set their user password

Answer 12:

Another thing that is worth noting is to set your user’s status is_staff as active. At least, that’s what makes it works for me. For more detail, I created another superuser as people explained above. Then I go to the database table auth_user and search for that username to make sure its is_staff flag is set to 1. That finally allowed me to log into admin site.

Answer 13:

Create a new superuser with the command “python createsuperuser”.
Login as the new super user. Click on the ‘users’ link. Then click on the user you want to delete. click on delete user at the end of the form page.

Note – The above process will make changes to the activity logs done by that particular user.

Answer 14:

if you forget your admin then you need to create new user by using

python createsuperuser <username>

and for password there is CLI command changepassword for django to change user password

python changepassword <username>


django-admin changepassword <username>

OR Run this code in Django env

from django.contrib.auth.models import User
u = User.objects.get(username='john')
u.set_password('new password')