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: abc@gmail.com

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.


Related Topics

Django Filters

Django is a high-level python based web framework. Django is mostly used as a backend engine for websites. Nowadays, every website communicates to a database to fetch all the information...

3 minutes read.

Django Forms

Django is a Python Programming Open Source framework for web development. It was released in 2008 and was developed by two web developers named Adrian Holovaty and Simon Willison. It...

3 minutes read.

Django Installation

Django Installation Django development environment consists of installing and setting up Python, Django, and a Database System since Django deals with a web application. Below the statement will guide you through installing Python 3.8.0 and...

2 minutes read.

Django CMS vs WordPress

Both Django CMS and WordPress belong "Self-Hosted Blogging" or "Content Management System (CMS)" category, that is used to manage digital content. Bloggers usually use these platforms. Django CMS Django is one of...

4 minutes read.

Django Messages

Django Framework Django is a framework that can make web applications more accessible and faster. Django is an open-source collection of python libraries, and Django can be used for both the...

6 minutes read.

Django Framework

Django is a popular high-level open-source web development Python framework based on follows Model View Template (MVT) architecture that allows rapid development. It. It provides common functionality like Admin Interface,...

3 minutes read.

Life Cycle of Django

Life Cycle of Django Request - Response life cycle in Django  Thebasic principle of http protocol is the client sends a request to the server based on the request data, and the server sends...

3 minutes read.

Django Tutorial

Django Introduction It is a web application framework written in a python programming language. It based on the MVT( Model View Templet) design pattern. It takes a short time to build an application...

2 minutes read.

Django Pagination

Django is an open-source free to use python based web framework. Django provides many inbuilt tools for web developers to provide rapid web development. One of these tools is pagination....

4 minutes read.

Django Model Fields

In Django, if we want to store the information about anything, we use Models. It contains various fields about the data. Generally, each model represents a database where all the...

4 minutes read.

How to create an app in Django

Create an application in Django Django is famous for its unique and fully managed application structure. For each functionality, an application can be created as a completely independent module. This article will take...

2 minutes read.

Django Celery

Django is a python-based web framework. It is an open-source and free-to-use framework. Django uses the Model View Template architecture. Django provides many functionalities to web developers. One of these...

3 minutes read.

Django CSRF

Django is a high-level python based web framework. Django is open source and free to use for all. Django provides many features to web developers like scalability, security, rapid development,...

4 minutes read.

Django and React

This article will discuss the overview of Django and React, their advantages, applications, and most importantly, how to implement react in Django. What is Django? Django is a free and open-source web...

6 minutes read.

Best Django courses

In this tutorial, we will see various courses in python Django available on the internet. Django has become popular these days, so courses on it are also increasing day by...

7 minutes read.

How to connect Django with Mysql

Any web application contains some data that comes from the input of the end-users. Thus, the database is required to handle those data. Several databases could be used to connect...

3 minutes read.

Django Stack

Django is a popular Python web application framework that adheres to the "batteries-included" tenet. Batteries-guiding included idea is that common functionality for creating web applications should be provided with the...

5 minutes read.

Django vs Laravel

Django Overview Django is a Python Programming Open Source framework for web development. It was released in 2008 and was developed by two web developers named Adrian Holovaty and Simon Willison....

4 minutes read.

Django ORM

Django is a Python web framework that enables easy and quick web development. Django has a handy and powerful feature called Django Object Relational Mapper, also known as Django ORM,...

3 minutes read.

Django Create Project

Django is an open-source free to use web framework which is based on Python. Django uses Model-View-Template as its architecture. The final version of Django was released in 2008. Django...

4 minutes read.