This article is written on a certain purpose for defining about how to create an account which is a super user account in web-based application powered with Django web-based framework. The account itself will be used to log to the admin page. The most important thing is to have the table named ‘auth_user’ after executing certain command. Those commands are shown below :
1. Assumed that Django has been already installed, below is the command to create a new project :
django-admin startproject myproject
2. After the project has been successfully created, below is the command to create a new app within the project or inside the project
django-admin startapp myapp
3. The next step is the step for creating a new user which is done by executing the following command :
python manage.py createsuperuser
The output generated from the above executed command can be shown as follows :
user@hostname:~/myproject$ python manage.py createsuperuser Username (leave blank to use 'user'): root Email address: root@local.myapp.web Password: Password (again): Superuser created successfully. user@hostname:~/myproject$
In order to prove whether the account has been created or not, below is the content or the record inserted after creating a new super user :
user@hostname:/opt/pycharm-community-2017.3.1/bin$ psql -Upostgres Password for user postgres: psql (9.5.9, server 9.3.10) Type "help" for help. postgres=# CREATE USER test WITH PASSWORD 'test'; CREATE ROLE postgres=# CREATE DATABASE school OWNER test; CREATE DATABASE postgres=# use test; ERROR: syntax error at or near "use" LINE 1: use test; ^ postgres=# \c test psql (9.5.9, server 9.3.10) You are now connected to database "test" as user "postgres". test=# \dt List of relations Schema | Name | Type | Owner --------+--------------------------------+-------+------- public | auth_group | table | test public | auth_group_permissions | table | test public | auth_permission | table | test public | auth_user | table | test public | auth_user_groups | table | test public | auth_user_user_permissions | table | test public | django_admin_log | table | test public | django_content_type | table | test public | django_migrations | table | test public | django_session | table | test (13 rows) test=#
As shown in the above output of the database named ‘test’ used from the application. It reveals a table named auth_user which is used to create a new created user. The user which is created from the above command. In order to make sure the user’s data, just select :
test=# select * from auth_user;
Below is the output of the PostgreSQL Query executed :
id | password | last_login | is_superuser | username | first_name | last_name | email | is_staff | is_active | date_joined ----+-------------------------------------------------------------------------------+-------------------------------+--------------+----------+------------+-----------+---------------------------+----------+-----------+------------------------------- 1 | pbkdf2_sha256$24000$kd1kvyrKbx0p$LMb66uCdzS+jQK/6a/OZm8V6C52tM8S9hmdHKnG/DnE= | 2018-01-13 10:31:09.863052+07 | t | root | | | root@local.myapp.web | t | t | 2018-01-13 10:30:52.614766+07 (1 row) (END)
For further checkup, it can be done by accessing the admin page and try to log into the admin dashboard panel as shown below :
Just use the account created in the previous step which is ‘root’ and the try to login to the administrator panel of Django web-based framework where it can be accessed in the URL of : http://localhost:8000/admin. Basically the URL is an URL provided for a development testing. It is done by executing the command below :
python manage.py runserver
If the root account or any other name used for the super user account has successfully created, the following administrator panel of Django web-based framework will be successfully accessed based on the username and the password previously given in the step for creating the user :
One thought on “How to Create Super User Account in Django”