create superuser in django

How to Create Superuser in Django

A superuser in Django website is the admin of your website and has the ability to make pretty much any change on the website. Django comes with a built-in admin interface for every website. However, only superusers will be able to access and use it. There are two ways to create superuser in Django – through command prompt/terminal or programmatically. In this article, we will look at how to create superuser in Django.

How to Create Superuser in Django

Here are the steps to create superuser in Django.

1. Using Terminal or Command Prompt

In this case, first you need to navigate to the folder of your Django project, which contains file.

Then run the following command to create superuser named john

$ python createsuperuser

You will see a prompt to enter desired username.

Username: john

Next, you will see a prompt to enter email address of user. You can leave it as blank, but it is useful to reset password in case you forget it.

Email address:

Next, enter & re-enter the password for user.

Password: ******
Password(again): ******

If all goes well, you will the following message indicating that the superuser is created successfully.

Superuser created successfully.

Now you can start the Django server with following command.

$ python runserver

Open browser and visit You will see the following page with login scree. Enter the new username and password to proceed.

2. Create Superuser programmatically

You can also programmatically create Django superuser. Run either of the following commands from terminal or from within your script. Replace john, and pass with your superuser’s username, email and password.

$ echo "from django.contrib.auth.models import User; User.objects.create_superuser('john', '', 'pass')" | python shell


$ echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('john', '', 'pass')" | python shell

That’s it. In this article, we have learnt how to create superuser in Django.

Also read:

How to Print in Same Line in Python
How to Import from Another Folder in Python
How to Enable Apache MPM Prefork
How to Change Apache Prefork to Worker
How to Enable PHP in Apache

Leave a Reply

Your email address will not be published.