Django Create Superuser

For managing the website, we need an Admin while creating the Django application. In order to create the admin user, create superuser command is used. The superuser is called the admin user. Django provides an inbuilt Admin Panel along with the authentication, which is not to be created separately. Migrating the Django project is necessary before creating a superuser database. There are three types of users:

  1. Regular User– No Admin Access
  2. Staff User – Restricted Admin Access
  3. SuperUser – Full Access

Options of Superuser

Django createsuperuser has various options that may be needed while customizing, like automating superuser creation or using different databases.

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]
OptionDescription
-h, --helpShow help message
--username USERNAMESpecify login name for the superuser
--noinput, --no-inputDjango will NOT prompt the user for any kind of input. Superuser will not be able to log in until given a valid password if it is created with this option. It can be used to automate superuser creation
--database DATABASESpecify the database to use. By default, it is "default."
--email EMAILSpecify email for the superuser
--versionShow program version 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 SETTINGSPython path to the settings module. By default, the DJANGO_SETTINGS_MODULE environment variable is used
--pythonpath PYTHONPATHDirectory to add to the python path
--tracebackRaised on CommandError exception.
--no-colorDo not colorize command output
--force-colorForce colorization of command output
--skip-checksSkip system check

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

--database, --settings, --pythonpath allows you to run the command with custom databases and settings.

--no-color, --force-color can be beneficial for people with color blindness or messed terminals

Create Superuser

Step 1:

Run the following command

(cms) D:\Django\cms\djangocms>python manage.py createsuperuser

Step 2:

Enter username. By default, it is the system username.

Username (leave blank to use 'nikhil '): user1

Step 3:

Enter the email address.

Email address: [email protected]

Step 4:

Enter the password, and after pressing enter, you will be asked to enter the password again for confirmation.

Password:
Password (again):
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

If the password entered is common, you will be asked to bypass password validation. If you still want to use the common password, enter y and press enter else, press N, and create another not common password. After entering the password, the superuser is created successfully.

Step 5:

Now, login to the Admin page by running the following command:

(cms) D:\Django\cms\djangocms>python manage.py runserver


Watching for file changes with StatReloader
Performing system checks...


System check identified no issues (0 silenced).
July 27, 2021 - 12:21:51
Django version 3.2.5, using settings 'djangocms.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

In the browser, go to "/admin/" on the local server http://127.0.0.1:8000/ or "http://127.0.0.1:8000/admin/". The following page will appear.

Create Super User

Now enter the Username and Password set while creating the superuser.

The admin Page after a successful login will look like this:

Create Super User

Now you can create or change groups and users, which is provided by django.contrib.auth the authentication framework.