Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

django
superuser
communitycreator

How to create a superuser in Django

Abdul Monim Tariq Lodhi

Overview

We do not create a separate “Admin” page or provide an authentication feature because Django provides an “Admin” panel for its users. Furthermore, we must migrate to our project before using this feature; otherwise, we will not be able to create a database of superusers.

Simple steps to follow

We can create a superuser by writing the following command:

python3 manage.py createsuperuser

We then write the following credentials step by step. We can fill these credentials according to our preferences:

  • Username: testAdminUser

  • Email address: test@gmail.com

  • Password: ********

  • Password (again): ********

Note: After filling a row, press “Enter” to fill the other information.

Now the superuser will be created if we have entered all fields correctly.

Creation of superuser
Creation of superuser

Django’s “Hello World” application

A sample “Hello World” Django application is given below. We can follow the given steps to test our knowledge:

  • Start the terminal by clicking on the “Run” button.
  • Type python3 manage.py createsuperuser in the given terminal and press “Enter”.
  • The system will ask for credentials, after which a superuser will be created.
  • To run the server, we type the command python3 manage.py runserver 0.0.0.0:8000 and press “Enter”.
from django.db import models

# Create your models here.
  • Now we can find our application by clicking on the link below the “Run” button.

  • To see the login page for the Django “Admin” site, we need to append /admin/ at the end of our base URL. For example, if the application is running at http://127.0.0.1:8000, we can access the admin panel at http://127.0.0.1:8000/admin/.

Django "Admin" login page
Django "Admin" login page
  • Now we can type our username and password, then press the “Log in” button.

RELATED TAGS

django
superuser
communitycreator

CONTRIBUTOR

Abdul Monim Tariq Lodhi
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring