A2oz

How to Create an Admin User in Django?

Published in Django 1 min read

Creating an admin user in Django is a straightforward process that involves using the built-in createsuperuser management command.

1. Access the Django Shell

Open your terminal or command prompt and navigate to your Django project directory. Execute the following command to access the Django shell:

python manage.py shell

2. Use the createsuperuser Command

Inside the Django shell, type the following command and press Enter:

from django.contrib.auth.models import User
User.objects.create_superuser(username='admin', email='[email protected]', password='password')

This command creates a superuser with the username "admin," email "[email protected]," and password "password."

3. Access the Admin Panel

After creating the admin user, you can access the Django admin panel by navigating to http://127.0.0.1:8000/admin/. Log in using the username and password you just created.

4. Manage Users and Content

The Django admin panel allows you to manage users, create and edit content, and perform other administrative tasks.

Note: Remember to change the default password to a secure one for your production environment.

Related Articles