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:

Tutorial series on creating a basic Blog Application using Django

  1. Introduction to Django Framework and How to install it? (Part I)
  2. How to create your Django project and modify its settings. (Part II)
  3. Setting up Database for Django project and running Server(Part III)
  4. Creating Django Application and Introduction to Django Models(Part IV)
  5. 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/

create a Django SuperUser

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 a Django SuperUser

Create some posts, if you want to. Have a break!
That’s it!

Next part of this tutorial series:

What are Django URLs and How to create them(Part VII)

Feel free to drop any doubts regarding the tutorial in the comment section below.

Also, have a look at some other posts as well :


Leave a Reply

Your email address will not be published. Required fields are marked *