0
0
DjangoHow-ToBeginner · 3 min read

How to Create a Superuser in Django: Step-by-Step Guide

To create a superuser in Django, run the command python manage.py createsuperuser in your project directory. This command prompts you to enter a username, email, and password to set up an admin user with full access.
📐

Syntax

The basic syntax to create a superuser in Django is:

python manage.py createsuperuser

This command runs a script that asks for a username, email address, and password. The superuser created has full admin rights to manage your Django project.

bash
python manage.py createsuperuser
💻

Example

This example shows how to create a superuser by running the command and entering the required details.

bash
C:\myproject> python manage.py createsuperuser
Username (leave blank to use 'user'): admin
Email address: admin@example.com
Password: ********
Password (again): ********
Superuser created successfully.
Output
Username (leave blank to use 'user'): admin Email address: admin@example.com Password: ******** Password (again): ******** Superuser created successfully.
⚠️

Common Pitfalls

  • Not running inside the project directory: You must run createsuperuser where manage.py is located.
  • Weak passwords: Django requires a strong password; weak ones will be rejected.
  • Username or email already exists: You cannot reuse existing usernames or emails.
  • Database not migrated: Run python manage.py migrate before creating a superuser to ensure tables exist.
bash
Wrong way:
python createsuperuser

Right way:
python manage.py createsuperuser
📊

Quick Reference

CommandDescription
python manage.py createsuperuserStarts the superuser creation process
python manage.py migrateApply database migrations before creating superuser
python manage.py runserverRun the server to access admin panel after creating superuser

Key Takeaways

Run python manage.py createsuperuser inside your Django project directory.
Ensure database migrations are applied before creating a superuser.
Use a strong password to meet Django's security requirements.
The superuser has full access to Django's admin interface.
Avoid running the command outside the project folder or without manage.py.