it-guide

how to find your Django Admin username and reset your password

Hi, I'm Kitle.

Today, I’ll show you how to find your Django Admin username and reset your password. This guide is based on Django 3.x versions.

When you're managing multiple Django projects, it’s easy to forget which username or password you set for a specific admin panel. Since Django doesn't provide a "Forgot Password" feature in the admin UI by default (unless you've built it yourself), you need to handle this via the development environment.

Here is a quick and easy way to recover your access.


1. Navigate to Your Project

Open your terminal and move to the root directory of the Django project you are working on.

2. Locate manage.py

Ensure you are in the folder where the manage.py file is located.

3. Enter the Django Shell

Run the following command to enter the interactive Django shell:

python manage.py shell

If you see the >>> prompt, you have successfully entered the shell.


4. Fetch User Information

First, import the User model:

>>> from django.contrib.auth.models import User

(Note: It’s normal if no output appears after this command.)

Next, filter for superusers (admins):

>>> superusers = User.objects.filter(is_superuser=True)

5. Display the Results

Now, let's print the information to see the username:

>>> superusers
<QuerySet [<User: admin>]>

Django Shell Query Result

In my case, the superuser name is "admin". If no results are returned, double-check your typing. If it's still empty, you might not have created a superuser yet. In that case, you'll need to create a new one.

Once you've found the name, exit the shell using Ctrl + D (or Ctrl + Z followed by Enter on Windows).


6. Reset the Admin Password

Now that you have the username, run the following command in your terminal:

python manage.py changepassword admin

*Replace "admin" with the username you found in step 5.

You will be prompted to enter a new password twice:

Changing password for user 'admin'
Password: 
Password (again): 
Password changed successfully for user 'admin'

Django Password Reset Result


7. Login to the Admin Panel

Finally, go to your admin URL (usually your-domain/admin) and try logging in with the recovered username and the new password.

I hope this helps you get back into your project quickly!

- Kitle