Docs Menu

Create an Admin Site

You can create a Django admin site to edit your application's data from a web interface. To learn more about the Django admin site and its features, see The Django admin site in the Django documentation.

1

Before creating an admin site, you must create a user who can log in to the site.

From your project's root directory, run the following command to create an admin user:

python manage.py createsuperuser

Then, your terminal prompts you for a username, email address, and password. For each prompt, enter the following information to create a user with the specified credentials and press "enter" after each entry:

Username: admin
Email address: admin@example.com
Password: <admin-password>
Password (again): <admin-password>

Replace the <admin-password> placeholder with your user's password.

2

Run the following code to start your server:

python manage.py runserver

Once your server is running, visit the http://127.0.0.1:8000/admin/ URL to see the admin site. This site displays the following login screen:

The login screen on the Django admin page.

Enter the username and password created in the previous step to log in to the site.

3

After logging in to the admin site, you can see the following information:

The initial content displayed on the Django admin site.

You can edit your project's authentication configuration by selecting the Groups or Users row in the Authentication and Authorization table.

To edit the data in the users sample collection, represented by your Viewer model, navigate to your project's sample_mflix/admin.py file and paste the following code:

from django.contrib import admin
from .models import Viewer
admin.site.register(Viewer)

Now, your admin site displays the following information:

The content displayed on the Django admin site after registering a model.
4

You can view the data stored in a Viewer object that has a name value of "Abigail Carter". You created this object in the Write Data to MongoDB step of this tutorial.

Click on the Viewers row of the SAMPLE_MFLIX table to see a list of viewers. The admin site displays the following list:

The list of viewers displayed on the admin site.

Then, click on Abigail Carter at the top of the list. The site displays the Name and Email of the selected viewer:

The information of your selected viewer.
5

To edit the email field of the viewer, select the box that contains the text "abigail.carter@fakegmail.com". Delete this text and replace it with "acarter1@fakegmail.com", as shown in the following image:

The updated email address of your viewer.

Then, click the SAVE button below the viewer's information to save your changes.

After completing these steps, you can access the Django admin site and use it to edit your Viewer objects.