Django has an admin site that allows you to test, monitor, and control your web app. This tutorial will show you how to create a superuser for the admin site and view your model that you have set up.
A superuser is a administrative user that has all permissions for a site. The superuser is all powerful, so don’t abuse it or your users will resent you.
Navigate to the root directory of your project and run the following command.
python manage.py createsuperuser
You will be prompted to create a user name and password. The email address is optional. Hit enter after each entry.
Username (leave blank to use 'root'): burger_admin Email address: Password: Password (again):
Note: you won’t see your password as you enter it for security purposes. You’ve now created a superuser that can log into your Django admin site.
In order to administrate the app we’ve been working on, we must add the model to admin site. Open the admin.py file located in the root directory of your app. Add the code below to add your models.
from django.contrib import admin from .models import Burger, Topping # Register your models here. admin.site.register(Burger) admin.site.register(Topping)
This adds the burger models to your admin site, allowing you to create models of specialty burgers.
Navigate to 127.0.0.1:8000/admin or localhost:8000/admin in your web browser to log into the admin site and review.
Let’s create our Avocado Cream burger. Click +Add next to Burgers. Enter Avocado Cream and click Save. Now, click +Add next to Toppings. Select Avocado Cream from the drop down, then type in Avocado, Cream Cheese and click Save.
We’ve now created our first burger model for our burger joint website!
Check out my next post in this series about the Django Shell.