To configure the Django Admin panel
1. Install Django and Create a Project (if you haven’t already)
pip install django
django-admin startproject myproject
cd myproject
2. Create a Django App
Inside your Django project, create an app to work with.
python manage.py startapp myapp
3. Register the App in settings.py
Open myproject/settings.py and add your app (myapp) to the INSTALLED_APPS list:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp', # Add your app here
]
4. Create a Model to Use in Admin
In your app’s models.py, create a model you want to manage via the Django Admin panel.
Example:
from django.db import models
class Product(models.Model):
name = models.CharField(max_length=100)
description = models.TextField()
price = models.DecimalField(max_digits=10, decimal_places=2)
def __str__(self):
return self.name
5. Register the Model in the Admin Panel
In your app’s admin.py, register the model to make it accessible in the admin panel.
from django.contrib import admin
from .models import Product
admin.site.register(Product)
6. Create the Database Tables
Run migrations to create the database tables for your app’s models:
python manage.py makemigrations
python manage.py migrate
7. Create a Superuser
To access the Django admin panel, you need to create a superuser (admin).
python manage.py createsuperuser
Follow the prompts to set the username, email, and password.
8. Run the Development Server
Start the Django development server to access the admin panel.
python manage.py runserver
9. Access the Admin Panel
Now, go to http://127.0.0.1:8000/admin/ in your browser. Log in with the superuser
credentials you just created.