← Back to Django Course | Chapter 8: Django Admin | Lesson 1 of 8

Introduction to the Django Admin

Django's admin is a ready-made dashboard where you can add, edit, and delete your database records without writing any web pages for it yourself.

What the Admin App Gives You

Django ships with django.contrib.admin already listed in INSTALLED_APPS and already routed in urls.py. It reads your models and builds list, add, edit, and delete pages for them automatically -- no HTML required from you.

Note: You can see it in any fresh Django project by visiting /admin/ after creating a superuser.

Example: What the Admin App Gives You

This is the line already present in a new project's urls.py that wires the admin app to the /admin/ path.

markup
urlpatterns = [
    path('admin/', admin.site.urls),
]
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}

Logging In

The admin is protected by a login screen. Only a user marked as staff (and usually a superuser) can sign in, so you need an account with those permissions before you can use it.

Example: Logging In

Running this command creates the account you'll use to log in to /admin/.

bash
python manage.py createsuperuser

⚠️ Run this command in your terminal.

Why Models Don't Appear by Default

Django doesn't guess which models you want managed in the admin. Each model must be registered in its app's admin.py, or the admin site simply won't list it.

Warning: A model with no admin.py registration is invisible in the dashboard even though it exists in the database.

Example: Why Models Don't Appear by Default

Adding this to an app's admin.py makes the Book model show up in the admin dashboard.

markup
from django.contrib import admin
from .models import Book

admin.site.register(Book)
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}
Common Mistakes
  1. Assuming the admin site is meant to be the public-facing part of a website instead of a private management tool.
  2. Forgetting that the admin only shows models you've explicitly registered, then wondering why a model doesnt appear'.
  3. Leaving the default /admin/ URL and default superuser credentials exposed on a real production deployment.
Chapter Summary
  • django.contrib.admin is a built-in app that auto-generates a full CRUD interface for your models.
  • It's enabled by default in a new project's INSTALLED_APPS and wired up in urls.py.
  • You still need to register each model before it appears in the admin.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.