Creating a Superuser

Make an admin account with createsuperuser.

Syntaxpython manage.py createsuperuser

To log into the admin you need a superuser account. Create one with the createsuperuser command, which prompts for a username, email and password.

Run migrate first so the auth tables exist.

Example

Example · bash
# Ensure auth tables exist
python manage.py migrate

# Create an admin account
python manage.py createsuperuser
# Username: admin
# Email: [email protected]
# Password: ********

When to use it

  • A developer creates a superuser account immediately after startproject so they can log into the admin during development.
  • A DevOps engineer creates a superuser non-interactively in a Docker entrypoint script using environment variables.
  • A developer uses the shell to reset a forgotten superuser password without access to the admin login.

More examples

Create superuser interactively

Runs the interactive prompt to create a Django superuser with full admin access.

Example · bash
python manage.py createsuperuser
# Prompts for username, email, and password

Create superuser non-interactively

Creates a superuser via environment variables without any interactive prompts, useful in CI/CD.

Example · bash
DJANGO_SUPERUSER_USERNAME=admin \
[email protected] \
DJANGO_SUPERUSER_PASSWORD=securepass123 \
python manage.py createsuperuser --noinput

Change password via shell

Resets a user's password programmatically through the Django management shell.

Example · python
# python manage.py shell
from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username="admin")
user.set_password("NewSecurePass!")
user.save()

Discussion

  • Be the first to comment on this lesson.