The Django admin site-Free Django Tutorials

The Django admin site ,For administrative activities django provides already build user interface.All developer knows how an admin interface is important for a web project.For your project models django automatically generates admin UI interface. Django’s automatic admin interface is the most powerful and important part.

Now let’s review the admin site in the blog project we are creating in our posts.In this post we will learn how to edit,add and delete the articles we have modeled using django admin.

First open the articles/admin.py file and replace it will following contents:

from django.contrib import admin
from .models import Article

admin.site.register(Article)

As you can see in the above code,we are importing the Article model we have defined in article/models.py file.To make our Article model visible on the admin page we need to register the model with admin.site.register(Admin).

Now it’s time to check our Article model.Run python manage.py runserver in the console to run the web server.After that go to your web browser and type http://127.0.0.1:8000/admin/. Where you will be able to see a login page.

To log in into the admin site you first have to create a superuser-which is a user account that has control over everything on the site.So for the purpose of creating a superuser go to command prompt and type python manage.py createsuperuser and press enter.

When screen is prompted,type in your username (which is supposed to be in lowercase with no spaces), email address, and password.You will not be able to see the password you are typing,so don’t worry about that.After completing details press enter.It will show a message like this:

The Django Admin SIte

[Note:email field is not necessary.You can leave it also]

After that go to server and login into the page using the same username and password you have created.When you login you will be taken to this page.

The Django Admin Site-1

Go to articles section from this page.After that add two-three articles from that page.For adding articles click on ADD ARTICLE+ button which is in the corner of below page.


The Django Admin Site

In the below page add title,slug and body part for each article and click on the save and add another button which is at bottom.

The Django Admin Site

Now you can see from the below that we have added three articles article1,article2,article3.

The Django Admin Site

Suppose if we want to know the details about particular article or suppose we want to edit or delete some particular article then we can do it by this way:

Suppose we want to know the detail about Article 1.So click on the Article1 in the above image.You will be redirected to this image.

The Django Admin Site

In the above image you can check the slug and body part of Article1 and suppose you want to change some field then you can also do editing of that part.When you are done with editing part just click on SAVE button to save the changes you have done.Suppose if you want to delete that article then you can click on Delete button.It will delete that article from our database.

To know more about django admin site you can refer to this https://docs.djangoproject.com/en/2.0/ref/contrib/admin/.


This is all about django admin site,how to create superuser,how to add,edit and delete articles through admin site.

Leave a Comment

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