Django Admin Panel

Django Admin Panel

The Django admin panel is a powerful tool provided by Django that allows you to manage your application's data without writing custom views or templates. It automatically generates an admin interface based on your models.
To use the admin panel:

  1. Create a superuser

This command allows you to create a SUPERUSER account in your Django project. A superuser has all permissions and access to the admin panel, allowing them to manage all aspects of the application. You need to create a superuser to access the admin panel. Run the following command in your terminal:

python manage.py createsuperuser

When you run the command, Django will prompt you to enter information for the superuser account:

  • Username: The desired username for the superuser.

  • Email address: The email address associated with the superuser.

  • Password: The password for the superuser account. Django will prompt you to enter the password securely (it won't display as you type).

  • Password confirmation: Confirm the password by entering it again.

You can now use the username and password you provided to log in to the Django admin panel (/admin) using the superuser account. This account has access to all features and can manage all data in the admin panel.

  1. Register your models

When working with Django's admin panel, you need to register your models so that they are accessible and manageable through the admin interface. This involves importing your models and registering them with the admin site. In your admin.py file within your app directory, import your models and register them. For example:

from django.contrib import admin
from .models import Employee

admin.site.register(Employee)
  1. Access the admin panel

Once your models are registered, you can easily access the admin panel by simply visiting localhost:8000/admin in your web browser while your Django development server is running.

  1. Manage your data

Once logged in to the admin panel, you'll see a list of registered models. Clicking on a model will take you to a page where you can view, add, edit, and delete instances of that model.

By registering your models with the admin panel, you provide a convenient way to manage your application's data without writing custom views or templates. This is especially useful during development and for administrative tasks in production environments.