How to create a Django SuperUser and a look at Django Admin (Part VI)
In this tutorial, we are going to learn how to create a Django Superuser to control the posts we have created and will also look at the Django Administration window which has already been provided by Django.
This tutorial is a part of our series on Creating Blog Website using Django.
Link to the Previous tutorials:
- Introduction to Django Framework and How to install it? (Part I)
- How to create your Django project and modify its settings. (Part II)
- Setting up Database for Django project and running Server(Part III)
- Creating Django Application and Introduction to Django Models(Part IV)
- Creating Django Models and their Tables in the database(Part V)
Django Admin Window
To put the Posts model we created under the control of Django admin; so that in order to create, edit and delete posts, open the blog1/admin.py file in any code editor. In that, remove everything and add:
from django.contrib import admin from .models import Post admin.site.register(Post)
To make our Posts visible on admin page, we have imported (include) the Posts in admin.py file.
Now, run the website on your machine using:
python manage.py runserver
And then go to the address http://127.0.0.1:8000/admin/
Creating a SuperUser – Django
To log in, we need to create a superuser. For that run, the following command in a separate Terminal/console:
python manage.py createsuperuser
After then enter email address, username and password, when asked
Username: aayush Email address: [email protected] Password: Password (again): Superuser created successfully.
Then, in the admin window enter the following details to Log in. Then you will be redirected to the Admin dashboard.
Create some posts, if you want to. Have a break!
Next part of this tutorial series:
Feel free to drop any doubts regarding the tutorial in the comment section below.
Also, have a look at some other posts as well :