Accessing the Django Admin Site

When you ran startproject in Chapter 2, Django created and configured the default admin site for you. All you need to do now is create an admin user (superuser) to log into the admin site. To create an admin user, run the following command from inside your virtual environment:

  1. python manage.py createsuperuser

Enter your desired username and press enter:

  1. Username: admin

Django then prompts you for your email address:

  1. Email address: admin@example.com

The final step is to enter your password. Enter your password twice, the second time to confirm your password:

  1. Password: **********
  2. Password (again): *********
  3. Superuser created successfully.

Now you have created an admin user, you’re ready to use the Django admin. Let’s start the development server and explore.

First, make sure the development server is running, then open a web browser to http://127.0.0.1:8000/admin/. You should see the admin’s login screen (Figure 7-1).

Accessing the Django Admin Site - 图1

Figure 7-1: Django’s admin login screen.

Log in with the superuser account you created. Once logged in, you should see the Django admin index page (Figure 7-2).

Accessing the Django Admin Site - 图2

Figure 7-2: The Django admin index page.

At the top of the index page is the Authentication and Authorization group with two types of editable content: Groups and Users. They are provided by the authentication framework included in Django. We will look at users and groups later in the chapter.