Gareth D.
—You’ve forgotten your password and/or username for the Django admin panel. How can you get access to the admin panel again?
The easiest way to reset your password is by using the Django manage.py
script, which includes a changepassword
command. For example, if you know that the username for the admin account is admin
, you can reset it by running the following code:
python3 manage.py changepassword admin
You’ll be prompted for a new password and after entering it twice, you’ll be able to log into the admin panel through the UI using that password.
Changing password for user '<[email protected]>' Password: Password (again): Password changed successfully for user '<[email protected]>'
There are a few other ways of resetting a password or finding a lost admin username that may be easier for you depending on your exact setup. You can reset a password at different levels of the Django application, including:
manage.py
script.Generally, it’s safest and easiest to use the UI if you can and the command line script if necessary. You should avoid editing the database directly unless you know exactly what you are doing and have no other option, as it’s easy to break or corrupt your database by running database queries directly.
If you have access to another Django admin account, you can see all usernames and reset the password for the admin account you’ve forgotten by going to the “Users” page and using the reset password form.
Alternatively, you can promote another user account that you do know the credentials for to “Superuser status”.
manage.py
scriptYou can use the changepassword
command as demonstrated earlier. If you can’t use remember the username either, you can create a new admin account using the createsuperuser
command. Run:
python3 manage.py createsuperuser
You will be prompted for a new username and password for a new admin account. You can then use the new admin account to find the username and/or reset the password of the existing account through the admin panel, as above.
If you just want to be reminded of your admin account’s username and you can access the database directly, run:
SELECT username, email from users_customuser WHERE is_superuser;
This will return a list of all existing administrators. Your users might be stored in a different table, in which case you can run one of the following commands (depending on which database you’re using), to see all tables, and then substitute the correct table name in the above query:
\dt; # postgres .tables # sqlite SHOW TABLES; # mysql
NOTE: this is a potentially destructive operation. Proceed with caution.
If you want to promote a normal user to admin and you only have access to the database, you can run a query similar to the following. Note that updating the database can lead to problems and you should not do this unless you have exhausted all the above alternatives. Substitute the username you want to promote at the end, and, if necessary, the table name as described above.
UPDATE users_customuser SET is_superuser=true, is_staff=true WHERE username='admin';
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at [email protected].
If you are a California resident, see our Supplemental notice.