# TOPIC: Creating a Django Superuser
## Meaning of a Superuser
A **Superuser** is the administrator of a Django application. A superuser has full permissions to manage the project through Django's built-in **Admin Panel**.
A superuser can:
* Add new records
* View records
* Edit records
* Delete records
* Manage users
* Manage all registered models
Think of a superuser as the **system administrator** or **owner** of the application.
---
# Prerequisites
Before creating a superuser, ensure that:
* Django is installed.
* Your project is created.
* The database is connected.
* You have run the migrations:
```bash
python manage.py migrate
```
### What we are doing
We are creating all the required Django database tables, including the table that stores user accounts.
---
# STEP 1: Open the Terminal
### What we are doing
We are opening the terminal or Command Prompt in the Django project folder where the `manage.py` file is located.
Example:
```text
student_portal/
│── manage.py
│── config/
│── students/
```
---
# STEP 2: Create the Superuser
Run the following command:
```bash
python manage.py createsuperuser
```
### What we are doing
We are telling Django to create an administrator account.
### Meaning of the command
| Code | Meaning |
| ----------------- | ---------------------------------------------------------- |
| `python` | Runs the Python interpreter. |
| `manage.py` | Django's management script used to perform project tasks. |
| `createsuperuser` | Creates a new administrator account with full permissions. |
---
# STEP 3: Enter the Username
After running the command, Django will ask:
```text
Username:
```
Example:
```text
Username: admin
```
### What we are doing
We are creating the login name for the administrator.
The username is used when logging into the Django Admin Panel.
---
# STEP 4: Enter the Email Address
Django will ask:
```text
Email address:
```
Example:
```text
admin@gmail.com
```
### What we are doing
We are providing the administrator's email address.
This field is optional by default, but it is recommended to provide one.
---
# STEP 5: Enter the Password
Django will ask:
```text
Password:
```
Example:
```text
********
```
### What we are doing
We are creating a secure password for the administrator account.
**Note:** For security reasons, the password will not be displayed as you type.
---
# STEP 6: Confirm the Password
Django will ask:
```text
Password (again):
```
Type the same password again.
### What we are doing
We are confirming the password to ensure it was entered correctly.
---
# STEP 7: Superuser Created Successfully
If everything is correct, Django will display:
```text
Superuser created successfully.
```
### What we are doing
Django has saved the administrator's account in the database.
---
# STEP 8: Start the Django Server
Run:
```bash
python manage.py runserver
```
### What we are doing
We are starting the Django development server so we can access the Admin Panel through a web browser.
---
# STEP 9: Open the Django Admin Panel
Open your web browser and go to:
```text
http://127.0.0.1:8000/admin/
```
### What we are doing
We are opening Django's built-in administration website.
---
# STEP 10: Log In
Enter the credentials you created:
* **Username:** `admin`
* **Password:** (the password you chose)
Click **Log in**.
### What we are doing
We are signing in as the administrator to manage the application's data.
---
# What You Will See
After logging in, you will see the Django Admin Dashboard.
If you registered the `Student` model in `students/admin.py`, you will also see a **Students** section where you can:
* Add new students
* View all students
* Edit student details
* Delete student records
---
# Summary
```text
Run migrations
↓
Create superuser
↓
Enter username
↓
Enter email
↓
Enter password
↓
Superuser created
↓
Run the server
↓
Visit http://127.0
.0.1:8000/admin/
↓
Log in to the Django Admin Panel
```
This is the standard process for creating and using a Django superuser.


0 comments:
Post a Comment