Admin Page

Django comes with a default admin site that allows us to do lots of things in the backend.

Before creating a user who can log in to the admin site, we need to create migration and database with the following command.

Migration

$ python manage.py makemigrations

Apply the mirgration

$ python manage.py migrate

Create admin login

$ python manage.py createsuperuser

Enter your desired username and press enter.

Username: admin

You will then enter your desired email address:

Email address: admin@example.com

The final step is to enter your password. You will be asked to enter your password twice, the second time as a confirmation of the first.

Password: **********
Password (again): *********
Superuser created successfully.

Start the development server

The Django admin site is activated by default.

We can start the development server python manage.py runserver and access our admin page at: http://127.0.0.1:8000/admin/

Try logging in with the superuser account you created in the previous step, and you’ll see the Django admin index page.

On the admin page, you can create new users, check your history and manage posts.

Make the app modifiable in the admin

To display our blog app on the admin index page, we access blog/admin.py file, and edit:

from django.contrib import admin
from .models import Post

# Register your models here.
admin.site.register(Post)