Open In App

How to create superuser in Django?

Last Updated : 17 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Django comes with a built-in admin panel that allows developers to manage the database, users and other models efficiently. This eliminates the need for creating a separate admin interface from scratch. To access and manage the Django Admin panel, we need to create a superuser i.e. a user with full administrative privileges.

Prerequisites

Before creating a superuser, ensure that

python manage.py migrate

This step ensures that the necessary database tables, including those for authentication, are created.

Steps to Create a Superuser

To create a superuser in Django, follow these steps:

1. Navigate to the Project Directory: Open your terminal or command prompt and move to the directory where your manage.py file is located.

cd path/to/your/django/project

2. Run the Superuser Creation Command: Execute the following command to initiate the superuser creation process:

python manage.py createsuperuser

3. Enter Required Details: The system will prompt you to enter details for the superuser:

  • Username: Choose a username for the superuser.

Username: admin

  • Email Address: Provide an email address (optional, can be left blank).

Email address: [email protected]

  • Password: Enter a secure password and confirm it when prompted.

Password: ********

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

Note: Ensure your password meets the security requirements set by Django. If it is too weak, Django may ask you to enter a stronger password.

4. Successful Superuser Creation: If all fields are entered correctly, you will see a confirmation message:

Superuser created successfully.

Image shown after above steps done 

Logging into the django admin panel

Once the superuser is created, follow these steps to log in:

1. Start the Django development server:

python manage.py runserver

2. Open your web browser and navigate to the Django admin login page:

http://127.0.0.1:8000/admin/

3. Enter the Username and Password you set while creating the superuser.

4. Click Login, and you will be redirected to the Django Admin Dashboard, where you can manage your application’s models, users and data.               

Django admin page

Additional Tips

  • Changing Superuser Password: If you forget the superuser password, you can reset it using:

python manage.py changepassword <username>

  • Creating Multiple Superusers: You can create additional superusers by repeating the createsuperuser command.
  • Managing Users via Shell: If needed, you can create or manage superusers using the Django shell:

python manage.py shell
from django.contrib.auth.models import User
User.objects.create_superuser('newadmin', '[email protected]', 'securepassword')

Related Articles:


Next Article
Article Tags :
Practice Tags :

Similar Reads