Django Admin Tutorial : Django create superuser

Django admin tutorial

Hello Techies,

We know that Django is one of the best frameworks of Python which provides many features including authentication, Admin panel, contact form, file upload and support, and much more. In this Django admin tutorial blog, we will see what features Django admin offers.

Django Admin Tutorial: Step By Step

Features of Django Admin:

  • This is a built-in application provided by Django Framework where you will get Admin Interface.
  • This application provides an administrator interface for CRUD operations without writing SQL queries.
  • It also provides a User permissions feature.

Steps to create a Django Project:

To create the Django app, we need to follow these steps:

  1. Python Installation
  2. Virtual Environment Installation
  3. Using pip package install the Django

The below command will help you to create a Django application.

django-admin startproject django_admin_panel

Finally, we have successfully created the Django application. Now, if you want to run this application, use the following command and run the application locally on the browser (127.0.0.1:8000)

python manage.py runserver

let’s move on to our main topic which is the Django admin tutorial. So, now we will check how to access the Django admin panel.

For Django admin, we are using the ‘django.contrib.admin’ app which you will get by-default installed in Django.

So to access Django Admin we first need to run the migration script so that you get all the models used for the Django admin panel.

Use the below command to run the migration scripts.

python manage.py makemigrations #1st command

python manage.py migrate #2nd command

Now all the tables that are required for the Django admin panel have been created. We will now run the admin URL, which gives Django by default when you create the Django app. This URL is present in the django_admin_panel/urls.py path.

Use http://127.0.0.1:8000/admin this URL you can access the Django admin interface.

We now need login credentials to access this Django admin dashboard. We need a superuser to login to the admin interface of the Django admin application. So let’s create a superuser for the Django admin panel.

Command for Django admin create superuser is below:

python manage.py createsuperuser

Note: Here I have a bypass password authentication error because I entered a short password so if you pass any strong password you will not get such an error.

So now using the created username and password you can login to your admin panel.

Admin panel will look like below after logged In.

This panel gives you user CRUD operation, User Permission, search & filter feature, and more.

Change Admin Site Header, title & Index title

By default you get Admin Site header and Admin Login header as a ‘Django administration’, and Admin site title and index title as ‘Site administration’, so if you want to change this text then for this you have to add 3 liner code to the urls.py.

Check the code below:

# django_admin_panel/urls.py

from django.contrib import admin
from django.urls import path

admin.site.site_header = 'TechPlusLife Blog Admin'
admin.site.site_title = 'TechPlusLife Blog Admin'
admin.site.index_title = 'TechPlusLife Blog Administration'

urlpatterns = [
path('admin/', admin.site.urls),
]

HTML before changing the Site Heading and title.

HTML after changing the Site Heading and title.

Here we have covered some topics like how to create Django application, how to run migrations, how to run the Django admin panel, how to create a superuser in the Django admin panel, and how to change the header, title name of Django admin panel.

Refer to their official site for more information


FAQ on Django Admin

  1. How does Django admin work?

    Django comes with a built-in admin domain interface. Django admin Dashboard allow site administrators to create, edit and publish content, manage site users, and perform other administrative tasks.

  2. What is Django admin username and password?

    To access the Django Admin Dashboard, we need a super user to login to the Django admin application, so to create a superuser use: python manage.py createsuperuser command. It will ask you for a username and password then just type your login username and password. This way you can create a Django admin username and password.

  3. Where are Django admin templates?

    The default Django Admin templates are located under the /django/contrib/admin/templates/ directory. This directory located in your Django installation inside your operation system or virtual environment.

I hope you understand all the steps which I have covered in this blog which is based on the Django admin tutorial. If you still have any queries regarding this Django admin panel, please comment below.

Leave a Comment