Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Handling Ajax request in Django
Next article icon

Prerequisites:

The Django Admin Interface is one of the most powerful features of the Django framework. It provides a ready-to-use interface for managing project data through models, allowing developers and site administrators to perform Create, Read, Update, and Delete (CRUD) operations with ease.

When we start a new Django project, Django automatically includes a built-in admin app (django.contrib.admin). This interface is a web-based dashboard that lets us manage the database content of your registered models.

It offers:

  • CRUD operations on models
  • User and permission management
  • Model-level customizations
  • A clean, responsive interface

This article explores how the Django Admin Interface works, how to access it, and how to customize it for your application.

Accessing the Admin Panel

Django provides a built-in admin interface accessible via your browser. To access it, first ensure your development server is running, to run the development server, use this command:

python manage.py runserver

Now, to access the admin panel open your browser and navigate to:

http://127.0.0.1:8000/admin/

You’ll be prompted to enter a username and password.

There are basically two ways to access the Django admin panel:

1. Superuser

  • Has full access to the admin panel and all models.
  • Can create, update, and delete any record.
  • Created using createsuperuser.

2. Staff User with Permissions

  • You can mark a user as astaff member (is_staff=True) and assign them specific permissions (e.g.,view,change,deletefor amodel).
  • Such users will also be able to log in to the admin panel but only see what they’re allowed to manage.

Example of creating a staff user (in a script or shell):

from django.contrib.auth.models import User
user = User.objects.create_user(username='editor', password='pass123')
user.is_staff = True
user.save()

Then use the Django Admin to assign model-specific permissions via the Users section.

Accessing the Admin with Superuser

Theadmin app(django.contrib.admin) is enabled bydefaultand already added to theINSTALLED_APPSlist present in thesettings.py file. If you don’t have a user yet, the quickest way to log in is by creating a superuser.

Run the following command in terminal:

python manage.py createsuperuser

Provide the required information:

  • Username
  • Email address (optional)
  • Password

Then start the development server:

python manage.py runserver

Go tohttp://127.0.0.1:8000/admin/, log in with your superuser credentials, and you’ll see the Django Admin Dashboard. From here, we can manage all registeredmodels,users, andsite data:

login

After logging in successfully, it shows the interface as shown below: .

Django Admin Interface

Reset Django Admin Password

To reset the superuser password, use the following command:

python manage.py changepassword <username>

Replace<username> with your actual superuser name.

Note:Ensure that the terminal is active in the directory wheremanage.pyis located before running this command.

Untitled-1
Changing password of the superuser whose username is Abhishek_Shakya

Registering Models in the Admin Panel

By default, only Django’s built-in models appear in the admin panel. To manage our own app models via the admin interface, we need to register them.

Before proceeding further, ensure that the Django project and app is already created, if not then refer to this article to learn to to create and setup a Django project and app.

Creating Django Project
Creating Django App

python manage.py createapp myapp

Step 1: Define a Model in models.py

Python
fromdjango.dbimportmodelsclassFacultyDetails(models.Model):first_name=models.CharField(max_length=100)last_name=models.CharField(max_length=100)department=models.CharField(max_length=50)def__str__(self):returnf"{self.first_name}{self.last_name}"

Step 2: Register the Model in admin.py

Python
fromdjango.contribimportadminfrom.modelsimportFacultyDetailsadmin.site.register(FacultyDetails)

Step 3: Apply Migrations

python manage.py makemigrations
python manage.py migrate

Once registered and migrated, our model will appear on the Django admin dashboard, ready for data manipulation.

Now the admin page will have the model FacultyDetails but make sure the server is up and running.

Django Admin Interface

Improve
Article Tags :
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp