Creating a Superuser
In this page:
Running createsuperuser
The createsuperuser management command walks you through setting a username, email, and password, then saves a User row with full admin rights.
Example: Running createsuperuser
This starts the interactive prompt; answer the username/email/password questions to finish.
python manage.py createsuperuser
⚠️ Run this command in your terminal.
What Makes an Account a Superuser
Behind the scenes, createsuperuser just sets two boolean flags on the User model: is_staff lets the account log in to /admin/, and is_superuser grants every permission without needing individual ones assigned.
Example: What Makes an Account a Superuser
Inspecting the created user in the shell confirms both flags were set to True.
python manage.py shell
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(username='admin')
>>> u.is_staff, u.is_superuser
(True, True)
⚠️ Run this command in your terminal.
Logging In and Confirming Access
Once the superuser exists, start the dev server and log in at /admin/ with those credentials to confirm the dashboard loads.
Note: If the login page rejects a correct password, double-check is_active is True on that user.
Example: Logging In and Confirming Access
Starts the dev server so you can visit http://127.0.0.1:8000/admin/ and log in.
python manage.py runserver
⚠️ Run this command in your terminal.
- Trying to log in to /admin/ with a regular user account that was never granted staff or superuser status.
- Forgetting the password immediately after creating the superuser in a non-interactive script.
- Creating a new superuser every time instead of reusing the existing one, ending up with several admin accounts.
- python manage.py createsuperuser starts an interactive prompt for username, email, and password.
- A superuser automatically has is_staff=True and is_superuser=True, granting full admin access.
- You need at least one superuser before the admin dashboard is usable.
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: