Django Create Superuser

When you create a Django application you’ll want to create an admin user that will manage the site. You will use the Django create superuser command for this. This top level admin user is called the superuser. There are 3 types of users in Django:

  • Regular users – don’t have any Django admin access
  • Staff users – able to log in to Django admin, but access is usually restricted
  • Superuser – able to do anything to any model in Django admin

Superuser is the top level admin of the site and has permissions to do anything that Django allows.

To create a superuser in Django you will use the createsuperuser command, like so:

(venv) ~/project$ python manage.py createsuperuser

Then it will prompt you for a username and password and you should have a superuser created.

Django createsuperuser also has a lot of various options, just like every other Django command. You would only need to use those if you are doing something pretty custom, like automating the creation of superusers or using a different database. 99% of users don’t need to worry about this.

usage: manage.py createsuperuser [-h] [--username USERNAME] [--noinput]
                                 [--database DATABASE] [--email EMAIL]
                                 [--version] [-v {0,1,2,3}]
                                 [--settings SETTINGS]
                                 [--pythonpath PYTHONPATH] [--traceback]
                                 [--no-color] [--force-color] [--skip-checks]

Used to create a superuser.

optional arguments:
  -h, --help            show this help message and exit
  --username USERNAME   Specifies the login for the superuser.
  --noinput, --no-input
                        Tells Django to NOT prompt the user for input of any
                        kind. You must use --username with --noinput, along
                        with an option for any other required field.
                        Superusers created with --noinput will not be able to
                        log in until they're given a valid password.
  --database DATABASE   Specifies the database to use. Default is "default".
  --email EMAIL         Specifies the email for the superuser.
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --force-color         Force colorization of the command output.
  --skip-checks         Skip system checks.

--noinput can be used to automate the creation of a superuser. You will have to specify --username and --email on the command line, and then set the password using code.

--verbosity and --traceback can be used to diagnose errors with createsuperuser.

--database, --settings, --pythonpath let you run your command with custom databases and settings.

--skip-checks can be used to bypass various system checks, can be nice in a dev environment where you don’t want to get side tracked fixing various issues unrelated to what you want to do.

--no-color and --force-color tell Django whether to colorize the output, can be useful for people with color blindness or to deal with messed up terminal colors.


Written by Eddie Svirsky

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top